Discord
Login
Community
DARK THEME

top down movement issues

I am trying to make it so when you use the arrow keys you move and I've done it only moves once per press so if I gold it it moves once and stops

heres my code

  playerY = 0
  playerX = 0
end

update = function()
  movement()
  
end

movement = function()
  if keyboard.press.LEFT then
    playerX -= 50
  elsif keyboard.press.RIGHT then
    playerX += 50
  elsif keyboard.press.UP then
    playerY += 50
  elsif keyboard.press.DOWN then
    playerY -= 50
  end
      
end

draw = function()
  screen.clear("blue")
  screen.drawSprite("player", playerX, playerY, 20)
 
end

keyboard.press[key] is only true if the input was pressed that frame, which is useful for things like buttons. In your case, you should remove ".press", resulting in keyboard.LEFT, keyboard.RIGHT, keyboard.UP, and keyboard.DOWN.

thank you so much! I am new to code and am making simple games to learn, this will help me a lot in the future!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community