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 / scolling 2D tiles as a whole?

Author
Message
steakyfask
13
Years of Service
User Offline
Joined: 9th Jan 2011
Location:
Posted: 15th Aug 2011 04:47
Hi, I know there are lots of posts on using 2D tilesets but I just can't get this right. I want my background to move and not the player ...

I Have my tileset.

I use dbCreateAnimatedSprite()
then inside my loop I create a 2D array for my tiles and then display using a for loop.

My problem is that I can't seem to move my tiles as a whole. any help please?


Here is my code so far.

Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 15th Aug 2011 20:48
It's only a question of calculating the correct coordinates for dbPasteSprite. Introduce xOffset and yOffset variables that show the current position of the top left corner of the visible screen. The offsets change when you press a direction key. Then paste the sprites by adding the offset to the coordinates.

Here is a simple test program to show you what I mean. I used just "X" characters instead of sprites, but the point is the coordinate calculation. This program does not limit the offset, but in a game you will need to do that, to keep player movement within certain limits.

Login to post a reply

Server time is: 2024-11-19 08:39:00
Your offset time is: 2024-11-19 08:39:00