[Solved] Scaling and jumpy looking movement


(Ethan) #1

I’ve run into an issue recently when trying to implement movement. I tried making a game with all entities being 32x32 images and then used FP.screen.scale to increase the size by 2. When I went to implement movement, I implemented velocity (with friction and acceleration) but I ran into the issue of getting really jumpy looking movement. I think it was due to using Numbers to handle all the movement values (Friction, Acceleration, Velocity) which caused the moveBy to get non-whole numbers. So basically on each frame when it goes to move, it is thrown off because it can only move a full pixel, not a half pixel.

How can I implement acceleration and friction without causing this sketchy movement? Do I have to make sure I use whole numbers when dealing with movement? And should I stick to using a screen.scale of 1 so that I can have greater precision?


(Nicole Brauer) #2

What I did in a game that had a really low resolution but in which I wanted fluid movement (using numbers, velocity and such) was to calculate the movement with numbers but then convert the result to an integer before setting the x and y of the player accordingly. Like this:

player_speed += accelaration;
player_speed *= 0.89;
(etc...)

player.x += int(player_speed);

I think it has something to do with FlashPunks camera and the way it handles non whole numbers but that helped me in getting smoother movement.

But that also depends on how fast your player is moving. If the movement is really slow maybe that solution wouldn’t help much and it would still stutter.

Another way would be to instead of doing “FP.screen.scale = 2” scaling all your entites by 2 (player.graphics.scale = 2) and setting the game resolution to twice the size. This will still make your game look pixelated but now the camera / player movement will be calculated “between” the pixels and is therefore smoother.

But this can also make it look a bit weird since it’s not pixel-perfect anymore and also depending on how you handle collision it can cause problems.


(Ethan) #3

Hmm, I tested it out and it seems to be the moveBy that gets jumpy and not the camera. However, it’s waaaaaaay more noticeable when you have a camera perfectly following the character.

I tried out your suggestion and casted the numbers and integers and it solved it. It’s perfectly smooth now even with the camera following it. I guess moveBy just gets confused by non-whole numbers :/. I would have guessed that it rounded the numbers itself.