Jump to content

Using many sprites for a few number of textures


woahReal
 Share

Recommended Posts

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?

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...