Friday, November 3, 2017

2d - Camera movement, Draw grid


If I have a 20x10 grid (640x320) where tiles are 32x32


The grid are rendered:


for (var y = 0; y < 10; y++) {
for (var x = 0; x < 20; x++) {

var tileX = Math.round(Camera.x / 32);

var tileY = Math.round(Camera.y / 32);

var tile = Game.map[tileY][tileX];

rect(x * 32, y * 32, 32, 32);

}
}

The camera follows a Player object and is in the middle on the canvas.



Camera position (x) are calculated such as:


Player.x - Camera.x + 320 > 640
Camera.x = Player.x - 320;

When the camera moves, it looks kinda solid (since it moves a whole tile). How can I make the movement a bit smoother? (Perhaps showing part of the next tile on either side, rather than the whole at once)




No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...