Jump to content

Moving a group down the screen


joey
 Share

Recommended Posts

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:

 

post-13168-0-46496500-1424039075.png

 

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

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

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

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...