PICO-8 Wiki
Advertisement

Coding[]

The solution of making the player move is to change the players x and y.

To do that we need to make 2 variables named x and y,

player = {x=0,y=0}

after we do that we need to actually draw the sprite so we need to make a draw function.

player = {x=0,y=0}

function _draw()
 spr(1,player.x,player.y)
end

Now we need to change the x and y.

player = {x=0,y=0}

function _update()
 if btn() then
    player.x += 1
 end
 
 if btn() then
    player.x -= 1
 end
 
 if btn() then
    player.y -= 1
 end
 
 if btn() then
    player.y += 1
 end

function _draw()
 spr(1,player.x,player.y)
end

If you do this then you are done!

Explanation[]

If i press the right (or the binded key) then the player.x is gonna add a one and the sprite will move cause its using the player.x.

-- Before i press right

0,0 1,0 2,0 3,0 4,0 5,0
0,1
0,2
0,3


-- After i press right

0,0 1,0 2,0 3,0 4,0 5,0
0,1
0,2
0,3


This goes for every direction.

Advertisement