Skip to main content
gamedev.net
🔒 Locked

Smooth Scrolling

Started by Magicdude 3 replies 1k views
Original Post
Magicdude
Magicdude
I am currently writing my own 2D, smooth scrolling, tile engine, and I have struck a problem. I have asked numerous people in the GameDev chat room, but no one can help. My problem is that whenever I near the bottom of the map, the program exits. I think that it is because it is reading outside the array, but I see no reason for it to be doing this since it works fine when scrolling horizontally and upwards, just not all the way down. If anybody can help, I would appreciate it. If you would like the executable so that you can visually see the problem, then please e-mail me at ChrisBarnaby@aol.com --------- Chris
Drone
Drone
I have no idea what your code looks like and you didn''t post it, but I will make a guess that you are overwriting the memory that contains the flag that you use to exit the game.

char buf[1];
bool done;

done = false;
while (!done)
{
// this will overwrite buf and if ''done'' is allocated
// just past ''buf'' then done will become non false or true
for (i = 1; i < 3; ++i)
buf = buf[i - 1];
}

- Brad Pickering
http://home.earthlink.net/~uubp/

Brad Pickeringhttp://home.earthlink.net/~uubp/Home for organically grown games
+AA_970+
+AA_970+
you probably are drawing outside of the vid mem you set for the map (i think this causes a game to exit?) because you go beyond the boundaries of the map. you should have something like

if(py < world_h)
{
move the map up;
}

px represents the y coordinate at the bottom of the screen and world_h is the size of the world. Both px and world_h should be in pixels not tiles, you probably could do it by tiles but this might cause problems when placing objects on the map as they would not be able to be placed between tiles or at a certain position within a tile.


Edited by - +AA_970+ on 3/5/00 12:13:06 PM
Muzzafarath
Muzzafarath
Drawing outside of video memory will make a program crash. But you shouldn''t move the map up when it hits the bottom, it just shouldn''t do anything.

if(py < world_h)
{
// do nothing
}

/. Muzzafarath
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
+AA_970+
+AA_970+
yea your right you should do nothing when the map is at the bottom, but the code is not what to do when your at the bottom but what to do everytime you need to move the map up (remember moving the map up takes you down), check to make sure py(the y coordinate at the bottom of the visible area) is less than world_h(the map''s height).
then if py is less than world_h - move the map up
if py is greater than or equal to world_h - don''t do anything, therefore map does not move

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.