Page 1 of 1

[SOLVED] Camera movement and tilemap issues

Posted: Mon Jun 19, 2017 1:59 pm
by Skere
First of all, the player/camera movement looks a bit rough at times in my game. I can't find the reason why. I already tried changing the player's step size/speed, but it doesn't seem to be the issue. My guess is that there's something wrong with the camera. I can probably fix this one myself with some more time.

More importantly, my tilemap looks a bit off. It's especially notable when it's downscaled, since it almost looks correct on fullscreen. Some lines between wood planks are a lot thicker than others.

How it should look (space between wood planks is constant)
Image

How it looks (space between wood planks is weird)
Image

Does anyone know why this happens? The relevant files are game/objects/World.lua and game/objects/Map.lua

Re: Camera movement and tilemap issues

Posted: Mon Jun 19, 2017 3:51 pm
by MrFariator
The problem you're experiencing has to do with scaling: you're scaling the map and character sprites at uneven pixel sizes, resulting in artefacting and fat lines of pixels as demonstrated by your screenshot. Here are the relevant lines of code:

Code: Select all

-- line 35 in World.lua
local scale = width() * 0.06 / game.maps.metadata.tileSize;

Code: Select all

-- line 58 in Map.lua
engine.graphics.draw(self.spriteBatch, 0, 0, 0, 0.8, 0.8);
The first may very well result in uneven pixel sizes due to computer math being what it is, while the other outright scales the size of the spritebatch by 20%. If you change scale and sx/sy factors of those lines to 1 you get the following result:

Image

Unless you're dealing with higher resolution assets, the rule of thumb for pixel art is to only render things at 1x, 2x, 3x or so forth, or implement a way to "blur" your pixels in order to create a virtual resolution, much like how Shovel Knight did it.

Re: Camera movement and tilemap issues

Posted: Mon Jun 19, 2017 4:05 pm
by Skere
Thanks, I'll have a look at it

Edit: Solved