Jump to content

Side scrolling


alex_h
 Share

Recommended Posts

I'm making a side scrolling game. All my level content is laid out by code within a flash / pixi like display list system. In order to optimise performance I was thinking that it might be a good idea to only draw items to canvas if they fall within a given range of the player, ie a distance that is slightly larger than the width of my canvas. Basically culling items that are currently offstage. Is this likely to save me much CPU time? Or are 'out of range' draw calls already ignored at some deeper level, further down the chain? I suspect the answer may well be 'it depends on which browser and which device your game is running on'...

 

Incidentally I did try to test this but ran out of time before I could get my test to work properly, so I thought I'd quickly ask here to see if anybody had any useful insights in the meantime!

 

thanks,
Alex

Link to comment
Share on other sites

I do a camera check and ignore any objects not visible to it, which is the same as what you're suggesting. It's a good point about testing if it actually makes any difference re: performance, but I suspect it should - I mean you can easily "skip over" objects that cannot be seen. So even if it doesn't help the rendering speed at least you're saving doing a whole load of javascript canvas calls, i.e. setting transforms, drawImage, etc - which is all just redundant if the object can't even be seen anyway. So I can't see how it would bench any slow (as long as your "in camera" routine is fast!)

Link to comment
Share on other sites

Thanks Rich, it should be a fast check, its just comparing the difference in x position between the player and each display object against a predetermined maximum value as part of the main draw loop. I'm hoping I'll be able to see some improvement from this on Samsung devices as I tested my game on a Galaxy Tab 2 yesterday and playback was a bit choppy in the good old Android Stock browser. The most obvious other way of speeding things up that springs to mind is to use a smaller canvas in the first place, which I am hoping to avoid! It wouldn't be the end of the world though as it's still very early days with this particular project.

 

[Edit] - incidentally I found what was stopping my test from working but it was still ultimately inconclusive since bizarrely the game seems to run less choppy on the Galaxy Tab today with or without the new code! I'll see if I can do some further testing on a lower spec device. 

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