I am a Playdate SDK newbie, and need help making a PNG in the "images" file into a sprite. My code looks like this:
import 'CoreLibs/graphics'
import 'CoreLibs/sprites'
-- import 'CoreLibs/input'
local gfx = playdate.graphics
-- playdate.inputHandlers.push(playdate.input)
local player = 1
local player = gfx.image.new('images/player.png')
local playerX = 0
local playerY = 0
local bullet = gfx.image.new('images/bullet.png')
local bulletX = 0
local bulletY = 0
local score = 0
AButtonDown = function()
BButtonDown = function()
end
end
function playdate.downButtonDown()
playerY = playerY + 10
down = true
up = false
left = false
right = false
end
function playdate.upButtonDown()
playerY = playerY - 10
down = false
up = true
left = false
right = false
end
function playdate.rightButtonDown()
playerX = playerX + 10
down = false
up = false
left = false
right = true
end
function playdate.leftButtonDown()
playerX = playerX - 10
down = false
up = false
left = true
right = false
end
function playdate.BButtonDown()
bulletY = playerY
bulletX = playerX
bulletTime = 1
end
function playdate.AButtonDown()
bulletTime = 0
end
function playdate.update()
gfx.clear()
gfx.image.draw(player,playerX, playerY)
if bulletTime==1 then
bulletY = bulletY - 3
gfx.image.draw(bullet,bulletX, bulletY)
elseif bulletTime==0 then
bulletY = playerY
bulletX = playerX
end
end
I have tried multiple different things, but have had no luck, so it would really help if someone could reply with the code I have, but modify it so the "bullet" and "player" images are sprites. Or just reply with an in-depth explanation of how to use sprites.
PS: I have tried "inside playdate" if you were wondering, and it didn't help either. Also if someone could explain collision rectangles, that would be a huge help.