joey Posted February 15, 2015 Share Posted February 15, 2015 Hi all, In my game I want to have a 2d array of sprites move down the screen (starting in -y territory / not visible). I have built a version of the game that works but I fear I am wasting a lot of resources and making the game run less smooth than it should. I would appreciate some advice on how to create my group(s) and sprites so that I maximize resource management. This diagram explains my question: I am fairly experienced with JavaScript and am looking mostly for advice (although code helps too!). Should this be one group? Should it be a group of groups (where each group is a row)? Should I simply use sprites for the entire thing? Thank you!,Joey Link to comment Share on other sites More sharing options...
rich Posted February 15, 2015 Share Posted February 15, 2015 I would say it all depends on the quantity of sprites we're talking about here. If you're talking thousands of them, then yes I would change approach for sure. If you're talking a few hundred then I would be less inclined to change. The camera can be set to automatically cull objects not in view, so although they exist they don't cost any rendering time. I'd explore this approach first personally. Link to comment Share on other sites More sharing options...
joey Posted February 16, 2015 Author Share Posted February 16, 2015 Thank you! Usage of camera cull is exactly what I was looking for. For me that should be the perfect solution because my 2d array will have between 50-150 sprites. Link to comment Share on other sites More sharing options...
rich Posted February 16, 2015 Share Posted February 16, 2015 Cull involves running a Rectangle.intersects check against the Sprite bounds and the Camera bounds each frame. Creating brand new objects is far more expensive than this. For 150 sprites I wouldn't worry too much. For more than this I would look at doing some kind of basic spacial tree. Link to comment Share on other sites More sharing options...
Recommended Posts