If you're having trouble with your Playdate device please contact support directly via the form at https://help.play.date/
Tips on what to include in your question:
- Have a clear title
- Provide what platform you're using the SDK on (Mac, Windows, or Linux)
I'm using SDK 2.5.0
I feel like I'm trying to do something really basic, but I have the order wrong and can't figure it out.
Problem:
- I have a sprite that I'm adding properties to. But when i try to access them they're nil. But then it's not. Sounds weird right. I'll try to break it down.
I'm currently running this in the SINGLE FILE EXAMPLES inside the sdk examples folder.
Here is my sprite (it's a menu)
import "CoreLibs/nineslice"
import 'CoreLibs/sprites'
local pd_nineslice <const> = playdate.graphics.nineSlice
-- -- import the nineslice image from images folder (or anywhere from your projects folder structure)
local nineslice <const> = pd_nineslice.new("assets/gridBackground", 5, 5, 16, 16)
-- -- local renderWidth <const>, renderHeight <const> = 10, 10
local renderWidth <const>, renderHeight <const> = 100, 100
-- -- local renderWidth <const>, renderHeight <const> = 200, 100
---@class Menu
---@field x integer
---@field y integer
class('Menu').extends(playdate.graphics.sprite)
function Menu:init(x, y)-- y, moveTo, pdedge
Menu.super.init(self)
self.xAxis = 3
self.yAxis = 3
self.Something = 42
self:moveTo(x, y)
self:setSize(100,100)
self:add()
end
function Menu:draw()
print("Is this a thing",self.xAxis, self.yAxis, self.Something)
nineslice:drawInRect(0, 0, renderWidth, renderHeight)
end
function Menu:addButton(button)
-- local menuX, menuY = self:getPosition()
-- local buttonWidth, buttonHeight = button:getSize()
print("Is this a thing",self.xAxis, self.yAxis, self.Something)
end
Then I run it using this:
import "menu"
Menu(50,50)
Menu:draw()
Menu:addButton("")
function playdate.update()
playdate.graphics.sprite.update()
end
Then add it to the main
-- Uncomment the import for the example you'd like to run --
-- import 'animator'
-- import 'arcs'
-- import 'audio'
-- import 'balls'
-- import 'blurdither'
-- import 'collisions'
-- import 'crank'
-- import 'drawmode'
-- import 'drawSampled'
-- import 'drawSampled2'
-- import 'fast_fade'
-- import 'file'
-- import 'gridview'
-- import 'icosohedron'
-- import 'imagesample'
import 'menuDemo'
-- import 'pachinko'
-- import 'perlin-distribution'
-- import 'perlin1'
-- import 'perlin2'
-- import 'perlin3'
-- import 'perlin4'
-- import 'perlinfield'
-- import 'sndtest'
-- import 'spritescaling'
-- import 'stencil'
-- import 'synth'
-- import 'tilemaptest'
-- import 'zorder'
if playdate.update == nil then
playdate.update = function() end
playdate.graphics.drawText("Please uncomment one of the import statements.", 15, 100)
end
When I do this though. I get the following in the console.
This is confusing O...o It's nil, but then I'm guessing after the sprite update it's not nil. Which begs the question. How am I to use it?
Before this became a demo page I had it in my game and it would just blow up because it's nil.
Thoughts?