So, I'm currently trying to simply make a sprite that looks like my PNG. Each time I try and build though it tells me Enemy is nil. Here's the main script:
import "CoreLibs/graphics"
import "CoreLibs/sprites"
import "CoreLibs/timer"
import "CoreLibs/object"
import "circle"
local pd <const> = playdate
local gfx <const> = pd.graphics
local playerX, playerY = 200, 120
local playerRadius = 10
local playerSpeed = 3
local function initialize()
local r = 20
local circleSprite = Circle(playerX, playerY, 20)
circleSprite:add()
local enemySprite = Enemy(100, 120, 20)
enemySprite:add()
end
initialize()
function pd.update()
gfx.sprite.update()
gfx.clear()
local crankAngle = math.rad(pd.getCrankPosition())
playerX += math.sin(crankAngle) * playerSpeed
playerY -= math.cos(crankAngle) * playerSpeed
playerX += math.sin(crankAngle)
gfx.fillCircleAtPoint(playerX, playerY, playerRadius)
end
The problem is when I try to initialize the enemySprite it tells me it's nill.
This is the script for what I'm trying to do but with the circle`local pd = playdate
local gfx = pd.graphics
class('Circle').extends(gfx.sprite)
function Circle:init(x, y, r)
Circle.super.init(self)
self:moveTo(x, y)
local circleImage = gfx.image.new(r * 2, r * 2)
gfx.pushContext(circleImage)
gfx.fillCircleAtPoint(r, r, r)
gfx.popContext()
self:setImage(circleImage)
`
That works, but when I try and put my custom enemy it doesn't.
Here's the enemy script:
local pd <const> = playdate
local gfx <const> = pd.graphics
class('Enemy').extends(gfx.sprite)
function Enemy:init(x, y, r)
Enemy.super.init(self)
self:moveTo(x, y)
local enemyImage = gfx.image.new("images/badguy")
gfx.pushContext(enemyImage)
gfx.fillCircleAtPoint(r, r, r)
gfx.popContext()
self:setImage(enemyImage)
end
Any ideas? The problem is that it won't let me put the enemy in, how would I make a sprite look like an image?