Punknoodles Posted August 18, 2017 Share Posted August 18, 2017 I'm developing a multiplayer game using Phaser, Node.JS, and socket.io. The world is much bigger than the screen. To optimize this, I want to be able to not render sprites that are off-screen. How would I do this? Is there a method that checks if a sprite is on screen at its current x and y coordinates? Or even a way to check if a worldx and worldy position is on-screen? Link to comment Share on other sites More sharing options...
tywang2006 Posted August 18, 2017 Share Posted August 18, 2017 I think you can define your render area as the windows size, for rest sprites off screen, you just do them as normal. when they are off screen, they wont be rendered so the performance shouldn't be a problem. I bet the performance is due to your massive word especial your background. it will be challenge for gpu. maybe you can check tilemap. Link to comment Share on other sites More sharing options...
JackAttack Posted August 18, 2017 Share Posted August 18, 2017 I think the inCamera property of the sprite does what you need here. Link to comment Share on other sites More sharing options...
Punknoodles Posted August 18, 2017 Author Share Posted August 18, 2017 1 hour ago, tywang2006 said: I think you can define your render area as the windows size, for rest sprites off screen, you just do them as normal. when they are off screen, they wont be rendered so the performance shouldn't be a problem. I bet the performance is due to your massive word especial your background. it will be challenge for gpu. maybe you can check tilemap. How would I do that? Link to comment Share on other sites More sharing options...
Punknoodles Posted August 18, 2017 Author Share Posted August 18, 2017 Figured it out, I guess it does it for me? From the Phaser.Camera docs: Quote ...and renders only those objects within its field of view. Link to comment Share on other sites More sharing options...
samid737 Posted August 18, 2017 Share Posted August 18, 2017 There is also autocull ---> example. Link to comment Share on other sites More sharing options...
Punknoodles Posted August 18, 2017 Author Share Posted August 18, 2017 1 hour ago, samid737 said: There is also autocull ---> example. Oh! That's what I need. But I'll have to test if the performance gains from not rendering the sprites (a bunch of bullets) are greater than the calculation cost the docs warn against. Link to comment Share on other sites More sharing options...
samme Posted August 18, 2017 Share Posted August 18, 2017 I think there's a way to simplify the bounds checks if you're not scaling or rotating any ancestors (I have to find it). I can't remember why autocull would be costly, since Phaser/PIXI has to calculate each sprite's transformation anyway in order to render it. For bullets it may be easier just to set a lifespan instead. Link to comment Share on other sites More sharing options...
Punknoodles Posted August 18, 2017 Author Share Posted August 18, 2017 Hmm, thanks for the answers everyone! I'm probably going to use autocull or lifespans. Link to comment Share on other sites More sharing options...
Recommended Posts