Another scrolling question!

BlitzPlus Forums/BlitzPlus Beginners Area/Another scrolling question!

macochran77(Posted 2012) [#1]
If I have a tile map and I want my image to stay centered while scrolling until it reaches edge of the tile map, how would I go about that? I know what I want it to do, but can't get my mind wrapped around it. It's a simple 2D program that scrolls multi-directional. I don't have any code far enough along for scrutiny. Any help would be greatly appreciated.


Midimaster(Posted 2012) [#2]
given ....

PlayerX = the position of the player in pixel (relativ to the playgrounds zero)
ScreenWidth= window size
MaxTilesX = Number of tiles in x direction of the whole playground
TileSize = Width of one tile

normaly you would show the tilemap with an offset of...

StartX = PlayerX-ScreenWidth/2


If the result is below zero you would set ....
StartX=0

If the result is behind (MaxTilesX*TileSize - ScreenWidth) you would set ...
StartX = MaxTilesX*TileSize - ScreenWidth

....Of course the same with Y

At the end you wil draw all tiles with these offsets

For i=0 to MaxTilesX
     For j=0 to MaxTilesY
          DrawImage TileImage , -StartX + i*TileSize ,  -StartY + j*TileSize
     Next
Next



mv333(Posted 2013) [#3]
Edge Independent Scrolling