Alex Tappin Posted April 8, 2016 Share Posted April 8, 2016 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! Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted April 8, 2016 Share Posted April 8, 2016 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; Quote Link to comment Share on other sites More sharing options...
Alex Tappin Posted April 8, 2016 Author Share Posted April 8, 2016 Ah, the texture. Thanks for that. What I have now is essentially CurrentSprite.visible = false NextSprite.visible = true. But I have multiple "sprites" when I only need one. Thanks for the tips. Excited to implement them. 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.