If your game has so many Sprites and Textures it can't run at a smooth 60 frames per second, you can use Replay's Pure Sprites to improve performance.
Only use Pure Sprites if you're having performance issues. They add additional complexity to your game and the potential for more bugs. Regular Sprites are still really fast!
You can create a Pure Sprite by passing an object into the
The Sprite object passed into
makePureSprite must have the methods
render is similar to a regular Sprite, but with only a
size parameter, and can only return Textures or other Pure Sprites. Pure Sprites do not have state or access to the
shouldRerender is how Replay optimises your Sprite. Based on the last frame's props and the current frame's props, you must return a
boolean of whether the Sprite needs to be redrawn. In our example above, if the
color prop doesn't change, we don't need to call
render again (since the return value will be the same). This caching can save time over many renders and improve your game's performance.
Pure Sprites share the same common props as Sprites.
Returns whether the render function needs to be called again based on the change of props. Reducing the number of renders can boost performance.
prevProps: Last frame's props.
newProps: Current frame's props.
Returns an array of Pure Sprites or Textures to render.
props: The props passed in by the parent Sprite.
sizefield of the Device object.
An alternative render method run if the device is in portrait. See Game Size for more.
An alternative render method run for large screens. See Game Size for more.
An alternative render method run for large screens if the device is in portrait. See Game Size for more.