VBfx / Tile tutorial / Step 1

Camera movement

Since the camera.X and .Y are just 2 Long values we can use them in any way we want, no matter if we store tile or pixel-based positions there. However the LookAt function needs to do additional conversions to check if the camera left the map. Basically we just have to multiplicate the map size by the TileSize to get it's size in pixel. This is done as shown below:

Public Sub LookAt( iX as Long, iY as Long )
    'Store position
    Camera.X = iX
    Camera.Y = iY
    'Check upper boundaries
    If ( Camera.X + Camera.w ) > ( Map.w * TileSize ) Then: Camera.X = ( Map.w * TileSize ) - Camera.w
    If ( Camera.Y + Camera.h ) > ( Map.h * TileSize ) Then: Camera.Y = ( Map.h * TileSize ) - Camera.h
'Check lower boundaries If Camera.X < 0 Then: Camera.X = 0 If Camera.Y < 0 Then: Camera.Y = 0 End Sub

I marked the changed parts, the other lines stayed the same as before. The lower-bound check of course stays the same as before, 0 remains 0.

Now the easy part is done, let's step on to the Draw function!