Jump to content

Delete child, Add child, Or...


Alex Tappin
 Share

Recommended Posts

Hello everyone, this is my first post on this forum. I have been using Pixi js for about 6 months now. I am using it as my rendering library for a sidescroller game I am developing for my senior project at my university. 

I stumbled across a post that mentioned using the sprites "visible" property. I just had a quick question on performance and what you guys would recommend.

While running through my sprite sheets, I was removing the child, and then adding the next sprite image every time my sprite needed to render the next sprite in the spritesheet! 

What I have done now is add each sprite to the stage upon initialization of my sprites. I also set the sprites visibility to false upon creation and make sure to only set the active sprite images visibility to true (the one I want to show) instead of deleting and re-adding. 

I suppose this will increase performance? Are there betters ways to go about this?

I will post some code examples in the morning when I am on a computer. Just wanted to post it here for now.

 

Thanks everyone!

Link to comment
Share on other sites

Unless you have at least 10k sprites inside container, everything goes.

Better way: change sprite texture.

//your way
var oldSprite = sprite;
container.removeChild(sprite);
sprite = new Sprite(myNextFrameTexture);
sprite.position = oldSprite.position;
container.addChild(sprite);

//canonic way
sprite.texture = myNextFrameTexture;

 

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