animated background

Hi there! I am planning to add an animated background to my game. My game is 2D tile based and I wanna know which is the best option for me.

I am planning different background animations depending the level (forest, desert, city,…).

My game is jump’n’run style game.

Should I use sprites in background? And about the performance?

Tks!

What type of animated background are you thinking about?

Most of the time when you want to have a scrolling background the most time efficient way to do it is to just draw an image.

Like this (for a side scroller) :


g2.drawImage(img,x,0,this);
g2.drawImage(img,x+imagewidth,0,this);
x-=scrollspeed;
if(x < -imagewidth) {
   x += imagewidth;
}

The player will not interact with the background. For example, in the jungle level, I wanna add an animated background of trees with monkeys jumping around.
In the dungeons level, I wanna add some mysterious eyes, snakes entering in holes, etc. But it is just for fun, the player will not interact with this background, only with the main screen. I hope that I made myself clear

it might be better to use sprites and smaller images to animate than using an animation that has several background images that are all rather large in size, it may cause slowdown. The best way to do it would probably make some sort of “layer” that stores all the things that go into that layer, and when it comes to drawing it, you merely draw the background and all the items in that layer.