Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Moving the background accross the screen (2D)

Author
Message
SPI
14
Years of Service
User Offline
Joined: 3rd Jun 2010
Location:
Posted: 12th Jun 2010 09:27
Hey guys,

So I have built my first game, it's like Mortal Kombat 2 with half the number of animations lol But anyway, I can't seem to figure out an algorithm to make the background move across the the x axis if the player hits either side of the screens edge.

Hope you understand what I mean by that. Also, does anyone know some good website where I could find license free sprites? I am no artist, my major hurdle when it comes to creating games is finding the appropriate sprites.

Thanks.
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 12th Jun 2010 20:10
You can move the background the same way as any other sprite, it's just a matter of calculating the coordinates. If the player should move right, then instead, the background sprite should move the same amount to the left. (Negative X coordinates are possible to slide it partly off-screen.)

There is only one catch. If your background is the same size as the screen, then part of the screen will be black as the background slides out of view. (This is not a problem if the background picture is larger than the screen but then the image consumes more memory as well, of course.) You can solve this in two ways.

One solution is to make two copies of the background sprite and move them in sync. As one copy slides out to the left, the other copy slides in from the right. (The two pictures must join seamlessly at the sides.)

The other solution is to apply texture scrolling. Then the sprite does not move at all, but the texture is drawn onto the sprite at different positions. One copy of the picture is enough but calculating the rotation amount can be a bit tricky. (Again, the two edges of the picture must join smoothly.)

If you have more than one sprite for background - so that the background is made of tiles - then you have to move all of them.

For an example of both tile moving and texture scrolling, have a look at my side-scroller demo, which is attached as a zip file to one of my posts in page 3 of the Dark GDK coding challenges thread.

http://forum.thegamecreators.com/?m=forum_view&t=150933&b=22&p=2

Login to post a reply

Server time is: 2024-07-04 10:28:18
Your offset time is: 2024-07-04 10:28:18