Moving, tiled background - performant way

Monkey Forums/Monkey Programming/Moving, tiled background - performant way

christianstrang(Posted 2012) [#1]
Hi :)
I'm currently working on a game with a moving background. I have one image (120x800) which I draw multiple times next to each other. This works fine, and I even can make it move, using an offsetX value that gets increased on every frame but I feel that this hits the performance quite a bit when a lot of interactions are happening simultaneously. Now I'm not sure if this is the correct way of doing this.

Is there an example in the bananas folder on how to do this or a performant code snippet I might take a look at?


Shinkiro1(Posted 2012) [#2]
The trick is to only draw the images that are visible to the player.
1) Calculate how many images you need to fit in the screen (DeviceWidth() / image.Width() + 1)
2) Loop the number of times you got from point 1 and draw your images


christianstrang(Posted 2012) [#3]
Ah, I get it, will try that! One more thing, my tiles are very simple (its basically just a simple background pattern). I could increase the size of the image, which would result in fewer pictures needed to be drawn. Performance-wise, is it better to have fewer images that are bigger (in my case 800x800) or more pictures that are smaller (in my case 120x800).

I would guess its better to use bigger images because you have less calls to the Draw-Engine, is that right?


christianstrang(Posted 2012) [#4]
Just realized that I can test that quite easilty, will try it and post my results here


MikeHart(Posted 2012) [#5]
It totally depends on the hardware you are running.