Repository navigation
Animations
Tiles can be animated by passing an animate: fn object into the map.makeAnimation handler. The animation is one dimensional function that depends on t, a time parameter, measured in seconds. The handler pushes a new function animate into an instance array, which later gets invoked by the global Animator instance.
The animate handler returns a function that updates the tile's object geometry and the tile's position (TODO: include walls?). When the Animator instance runs, these values will be updated in the render loop.
An animation can be declared as a trigger type by passing a trigger: fn object into the map.makeAnimation handler. A trigger animation is usually triggered by an event interaction. Otherwise, it is triggered on the init() call in the main process. A trigger animation differs from a conventional animation in that it is transient and not recurring. As such, the time parameter t that is passed into the function begins counting only when the event is triggered.
An additional controls object is passed into the function that allows one to determine the state of the animation, and call done() when the desired animation is completed.
To determine which geometries are animated and which ones are not, the animate function triggers an animating flag in the tile object. When the map is to be added to the scene, animating tiles are added as individual meshes while the rest of the stationary tiles are combined into a single geometry, and added as a single mesh.
This practice helps reduce the total number of geometries, without affecting the number of vertices that are required to be updated in the render loop.
As a safety precaution, the best practice will always be to declare tiles that are potentially animating using the declareAnimating method of the Map class.