How to move a sprite with directional inputs
Revision as of 15:12, 10 April 2020 by JoeStrout (talk | contribs) (Created page with "Directional (horizontal and vertical) inputs in Mini Micro are best detected using the <c>key.axis</c> method. This will respond to arrow keys, WASD, and any connecte...")
Directional (horizontal and vertical) inputs in Mini Micro are best detected using the key.axis
method. This will respond to arrow keys, WASD, and any connected gamepad/joystick. This gives the player maximum flexibility in controlling their character.
key.axis
returns a value from -1 to 1, with 0 being when no input is given. So, you can simply multiply this by the maximum amount you want to move the sprite, and add it to the sprite's x or y position.
Example
sp = new Sprite
sp.image = file.loadImage("/sys/pics/Wumpus.png")
display(4).sprites.push sp
speed = 10 // pixels per frame
while true
sp.x = sp.x + key.axis("Horizontal") * speed
sp.y = sp.y + key.axis("Vertical") * speed
yield
end while