-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|612|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Blogs Home -> Blogs


 
waroffice
Created : 12 August 2010
 

Smooth RPG tile map scrolling

Carry on from MNCN

This evening I have made the map scroll smoothly. It was a mathematical nightmare at first but I figured it out eventually.

Firstly I created an algorithm to render the map in an ever changing position depending on the position of the player on a pixel by pixel basis rather than tile by tile.

In order to know how much to offset the map render start position from I needed to know by how many pixels the player is into the current tile. This is a reletively easy task as long as you can remember your maths basics.

When dividing numbers that do not go into each other exactly you get a remainder.

EG:

17 / 5 = 3 r 2

We can do this quite easily in code

answer = 17 mod 5

Now lets apply this to the map system, if you <b><i>mod</i></b> the players position with the tile size it will give the number of pixels the player is into the next tile.

pOffX = Player.X mod 32

Because we want it to move the map left and up we make it negetive.

pOffX = -(Player.X mod 32)

Below is a screen shot of the code that includes the details for the Y axis and the map drawing statement.



The screen shot below details the player drawing statement and shows how the offsets are used to position the player in the correct location on screen.



This is the first time I have got this to work so well. I will try and remember the technique in the future.

Next on the list is map functions like loading new areas.

Until next time kids...

 

Comments