I'm having a problem where my player sprite, which usually moves smoothly, will occasionally move in a jumpy/laggy way for a couple of seconds at a time. The value of SCREEN FPS() is still 59-60. It also happens when using objects.
If I just move the player back and forth for a while, it will eventually happen.
This is a simplified version of the code I'm using:
#CONSTANT DIR_IMAGES = "media/images/"
#CONSTANT PLAYER_DAMPENING = 0.90
#CONSTANT PLAYER_SPEED = 0.5
SYNC ON
SYNC RATE 60
playerVelX AS FLOAT
playerVelY AS FLOAT
playerPosX AS FLOAT
playerPosY AS FLOAT
LOAD IMAGE DIR_IMAGES + "player.png", 100, 1
SPRITE 100, 0, 0, 100
WHILE (NOT SPACEKEY())
IF (RIGHTKEY()) THEN INC playerVelX, PLAYER_SPEED
IF (LEFTKEY()) THEN DEC playerVelX, PLAYER_SPEED
IF (UPKEY()) THEN DEC playerVelY, PLAYER_SPEED
IF (DOWNKEY()) THEN INC playerVelY, PLAYER_SPEED
INC playerPosX, playerVelX
INC playerPosY, playerVelY
playerVelX = playerVelX * PLAYER_DAMPENING
playerVelY = playerVelY * PLAYER_DAMPENING
SPRITE 100, playerPosX, playerPosY, 100
SYNC SLEEP 1
SYNC
ENDWHILE
END
Does anyone know what may be causing this, or have you run into it before?
Thank you.