Keyboard events help: Frameskips
Posted: Thu Jan 19, 2017 4:20 pm
Hello Guys,
I need some help solving a problem we have with some friends I am developing (prototyping) a game with.
Basically my task at the moment is basic movement to the player (at the time Im researching about input methods), what I have now is a 3x3 grid that is the board where the player is supposed to be moving in, the grid is like this, I draw the player at [0,0]
[-1,-1][0,-1][1,-1]
[-1, 0 ][ 0, 0][ 1, 0]
[-1, 1 ][ 0, 1][ 1, 1]
When the player press (up,down,right or left) it is supposed to move 1 time in that direction, but what I got is that I got some frameskips if I can name it like that, because I cant move with accuracy where I want, basically Im moving in the corners because I cant only get my keyboard to register one tap to the key, instead I got like I keep pressing down the key (I think is because im using isDown) tried with keypressed but no luck implementing that..
Here is my code, hope you can help, thanks in advance!
I need some help solving a problem we have with some friends I am developing (prototyping) a game with.
Basically my task at the moment is basic movement to the player (at the time Im researching about input methods), what I have now is a 3x3 grid that is the board where the player is supposed to be moving in, the grid is like this, I draw the player at [0,0]
[-1,-1][0,-1][1,-1]
[-1, 0 ][ 0, 0][ 1, 0]
[-1, 1 ][ 0, 1][ 1, 1]
When the player press (up,down,right or left) it is supposed to move 1 time in that direction, but what I got is that I got some frameskips if I can name it like that, because I cant move with accuracy where I want, basically Im moving in the corners because I cant only get my keyboard to register one tap to the key, instead I got like I keep pressing down the key (I think is because im using isDown) tried with keypressed but no luck implementing that..
Here is my code, hope you can help, thanks in advance!
Code: Select all
function Player:update(GridWidth,GridHeight)
if love.keyboard.isDown("right") then
if self.xStatus == 0 or self.xStatus == -1 then
self.x = self.x + GridWidth
self.xStatus = self.xStatus + 1
end
elseif love.keyboard.isDown("left") then
if self.xStatus == 0 or self.xStatus == 1 then
self.x = self.x - GridWidth
self.xStatus = self.xStatus - 1
end
end
if love.keyboard.isDown("up") then
if self.yStatus == 0 or self.yStatus == 1 then
self.y = self.y - GridHeight
self.yStatus = self.yStatus - 1
end
elseif love.keyboard.isDown("down") then
if self.yStatus == 0 or self.yStatus == -1 then
self.y = self.y + GridHeight
self.yStatus = self.yStatus + 1
end
end
end