Algorithm for scrolling tile based stuff
I have written code, which I think works, to basically scroll around a tile based world. Fascinating. My problem is on the game dev side. I''m trying to use my library to do a basic test and it''s not working. Here''s the idea behind how I scroll up and down:
IF SCROLL_DOWN
{
get info on the tile locate at (x, y+tileHeight)
also get info on tile at (x+tileWidth, y+tileHeight)
//why? in case the player isn''t evenly positioned over
//just one tile, in which case we need to check both to
//see if you can walk downwards
if both of these tiles are walkable
{
if we''re not at the edge of the screen, then
increment our y coordinate.
Otherwise, don''t increment Y, but scroll the world down.
}
ELSE IF SCROLL_UP
{
Same thing (decrement Y instead of incrementing though),
except that it checks these tiles:
(x, y-1) and (x+tileWidth, y-1)
}
It works fine if I haven''t scrolled yet After I''ve scrolled downwards, when I scroll back up, sometimes things are off, like the player will stop moving as if there''s a wall but there really isn''t one (not for a certain amount of pixels at least).
Basically, what algorithm would you use (assuming you had a working function to get info on a tile at a particular pixel coordinate and could pan your world just fine)? Is mine correct (then that means my lib is screwed up), or is there a better way to do it? Thanks a ton, I appreciate it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement