woahReal Posted June 16, 2020 Share Posted June 16, 2020 I am creating a game where there is a high variation in the number of sprites needed for a given texture. The popular "bunnymark" for pixijs accomplishes a similar need by creating a new sprite (from one of a few textures) whenever new bunnys are created, and the sprites persist for the duration of the webpage. However, in my game, sprites are liable to change between different textures often, so the problem is a little different. Should I create a new sprite every time the texture changes? Isn't this quite expensive? Is there a way to render a single sprite to multiple locations instead, provided I keep track of location and sprite in my game's logic? Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted June 16, 2020 Share Posted June 16, 2020 Sprite is light object, texture is light object, baseTexture is a big one. There will be many questions like that, so I advice you to clone the source code, open it in separate IDE window and look every time you use new class, learn which shortcut shows class by name Quote Link to comment Share on other sites More sharing options...
Exca Posted June 16, 2020 Share Posted June 16, 2020 Create sprites for each position you know you will have a sprite in, create new ones as needed and destroy old ones (without destroying the texture). Create textures of all the textures you have (put them in a spritesheet to get benefire of batch rendering) then just assign a texture to a sprite whenever it changes. You could also pool the sprites but that can bring lots of other issues depending on how it's done. And to answer the question about rendering single sprite to a multiple location. Sprite is basically doing just that. It renders the texture to a different location based on the position, scale and rotation of the sprite. (simplfied version of how it works, in reality there's plenty more happening). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.