Created
August 7, 2020 22:58
-
-
Save Jorger/9a72b0de753b11014b6de309b575fc49 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div className="game-grid-wrapper-character"> | |
{characters.map((character, index) => { | |
const left = | |
character[character.isRunning ? "destinationLeft" : "left"]; | |
const top = | |
character[character.isRunning ? "destinationTop" : "top"]; | |
const spring = useSpring({ | |
config: { | |
duration: 500, | |
}, | |
top, | |
left, | |
width: blockSize, | |
height: blockSize, | |
immediate: false, | |
onRest: () => { | |
const changeStates = endsCharacterAnimation( | |
characters, | |
gameGrid, | |
character.index, | |
isRunning, | |
blockSize | |
); | |
if (changeStates.updateGridCharacters) { | |
setCharacters(changeStates.characters); | |
setGameGrid(changeStates.gameGrid); | |
} | |
if (changeStates.updateIsRunning) { | |
setIsRunning(false); | |
} | |
if (changeStates.boardFinished) { | |
setBoardFinished(true); | |
handleBoardFinished(movementCharacter); | |
} | |
}, | |
}); | |
return ( | |
<animated.div | |
className="game-grid-character" | |
style={spring} | |
key={index} | |
> | |
<Character {...character.character} /> | |
</animated.div> | |
); | |
})} | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment