Sign in to follow this  

2D Side Scroller Help

This topic is 4488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone. I am sorry to post a new thread... maybe I should have continued my old one. Either way I don't think I really explained my problem well. So I will reword it here. Lets say you have a 32x32 tile set for your map. Then you create a nice beautiful 2d map (1 layer for simplicity). Then lets say you have a sprite, the player. You obviously want him to be able to move around this 2d map. He will need to be able to jump on rocks and die when he jumps off a cliff, or get damage when he is standing on lava. My unprofessional way of doing this is my having an array in memory. Each tile is represented with a different ascii value. For example, a map should be set up like so, 000000000 000002200 P00022000 113311111 111111111 The 0 will be the sky. The 2 will be bricks. The 1 will represent the ground. The 3 will represent lava. And lasty, the P will represent the Player's position in this map. In my design, P will be updated contantly. For example, if the player moves from his intial position + 32 pixels to the right, I will update the map in memory to look like the following, 000000000 000002200 0P0022000 113311111 111111111 In theory, this method works for what I want to do. However in practice, I have a small problem. When I increment the player's x position by 1, IE: player.X++, sometimes the values might get messed up if the buttons are pressed too fast or too rapidly. So even though the player has moved more than 32 pixels on the screen, in memory he may have moved only 28 which means the map hasn't been updated yet. I need the map to be updated accurately everytime the player moves 32 pixels from his last intial position. How can I go about this. My problem is not rendering a map, but rather how to accurately coincide with the graphical map with the array map that I have in System memory. Any help would be highly appreciated! Thanks in advance! -- Brandon Fogerty GOD Bless you Always!!!!!!!!

Share this post


Link to post
Share on other sites
I would suggest updating the position 'P' in the ascii map based on the absolute position of the player (player.X) rather than trying to update the map based on the movement of the player directly. Example:

tilex = player.X / 32;

then use whatever code necessary to make sure the 'P' is on tilex x cordinate.

hope that helps!

Share this post


Link to post
Share on other sites
Hey thanks Dwiel! So do you mean for example... if we take some arbitrary value for the player's x position on the screen like... 78, we say 78/32 which if we treat it as an integer type, that gives us 2.4 which would be 2. So then we say


Map[ground_value][1] = '0';
Map[ground_value][2] = 'P';

Is that what you mean? Thanks in advance!

-- Brandon Fogerty

GOD Bless you Always!!!

Share this post


Link to post
Share on other sites

This topic is 4488 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this