I have used Gamemaker Studio 2 before, briefly, and found that the
yprevious variables are extremely useful.
Since I am developing a pixel-based roguelike in LibGDX, what is the best way to implement this? I was using this logic:
- Create two variables,
- In the render loop (or in the player class) make
xby player speed
- Repeat 2 & 3
However, this seems to be very glitchy. Here is my render function:
player.xprevious = player.position.x; player.yprevious = player.position.y; if(movingRight) player.position.x += speed if(movingLeft) player.position.x -= speed; if(movingUp) player.position.y += speed; if(movingDown) player.position.y -= speed;
Since after this code the position is not being changed until the next iteration,
player.xprevious should be different?
Right after this, I logged the values of the variables, e.g.:
xprev 716.0, x 716.0 yprev 1435.0, y 1435.0
Help is greatly appreciated! Thanks.