Jump to content

Optimizing drawing sprites


OptimizationQuestion
 Share

Recommended Posts

Hello community!

What my game demands

My game is round based and in every round I spawn certain types of powerups that can be picked up by players. In the settings before the game starts it is already decided what types of powerups will spawn, but the server generates on the fly the next powerup that needs to spawn with the following information: time its spawns, the type of powerup, the coordinates where it needs to be rendered. This information is sent to the clients, which then render the next powerup on the screen. To give a concrete example: In a game powerups of 3 different types can spawn, then every few seconds the server sends the command to the clients to render a powerup of type z at position (x, y). If a round goes 3 minutes, it could mean that for example around 60 powerups (new sprites) will spawn.

How I solve it currently

Each powerup has its own class with a static texture (PIXI.Texture.from(path to svg file)) which loads a .svg file. If the client received the command to spawn a powerup, a new sprite is created (new PIXI.Sprite(powerupClass.texture)) and certain properties of this new sprite are defined (setTransform(x, y), width, height, anchor). Afterwards the sprite is added as a child to the powerup PIXI.Container(). When a powerup is picked up, I loop through the children of the container and remove the correct child based on its id. As you can see I already re-use the texture of each powerup, so multiple new sprites are created from a single texture again and again.

My question is if there is any obvious way to optimize this further? Or is this something where I should not invest any effort into optimizing it since any optimization would see almost no performance gains?

Link to comment
Share on other sites

well, you can change texture of existing sprite, if your object changed.

As for re-using old sprites for different objects - sprite pools shouldn't be used in js games before you actually now for sure that they are needed, yes, it removes some allocations but it makes your code ugly and bugs spawn from it.

Edited by ivan.popelyshev
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...