The problem : I'm trying to display some text, but it doesn't show up.
I've seen
and
I see Matts comment on drawing it in the sprite
But all of it STILL isn't clicking for. After looking through so many post I'd like to make the post rule them all. I'll even go as far as making an example on github to link too, but I have to understand HOW to show text.
Problem context: I have many things on screen here:
Those two boxes are what I want to show text in..
How am I doing it well.... It's a bit involved but only because I broke it down.
I first made a generic progress bar by doing this.
progressBar.lua
function ProgressBar:init(x,y,width,widthRemaining)
local progressBarBorderImage = gfx.image.new("images/progressBarBorder")
local progressBarImage = gfx.image.new("images/progressBar")
progressBarBorder = gfx.sprite.new()
progressBarBorder:setImage(progressBarBorderImage)
progressBarBorder.width = widthRemaining
progressBarBorder.remainingFuel = width
progressBarBorder:moveTo(x,y)
progressBarBorder:add()
self:setImage(progressBarImage)
self.width = width - 4
self.remainingFuel = widthRemaining - 4
self:moveTo(x,y)
self:add()
end
I then inherited this class in my fuelGauge class
fuelGauge.lua
local pd <const> = playdate
local gfx <const> = pd.graphics
import "ProgressBar"
class('FuelGauge').extends(gfx.sprite)
local progressBar = nil
function FuelGauge:init()
FuelGauge.super.init(self)
progressBar = ProgressBar(76,215,145,145)
progressBar:add()
end
function FuelGauge:updateFuelGauge(newwidth)
progressBar:setClipRect(progressBar.x-progressBar.width/2,progressBar.y-progressBar.height/2,newwidth,progressBar.height)
end
I then added this to my hudUI class
along with everything else on my hud
hudUi.lua
import 'CoreLibs/sprites'
import "coreLibs/object"
import "coreLibs/graphics"
import "FuelGauge"
import "HeatGauge"
import "Background"
import "TopOfScreen"
local pd <const> = playdate
local gfx <const> = pd.graphics
local backgroundImage = gfx.image.new("images/background")
local backgroundImage = gfx.image.new("images/background2")
local fuelGauge = nil
local heatGauge = nil
local background = nil
local tos = nil
class('HudUi').extends(playdate.graphics.sprite)
function HudUi:updateFuelGauge(remainingFuel)
fuelGauge:updateFuelGauge(remainingFuel)
end
function HudUi:updateHeatGauge(heat)
heatGauge:updateHeatGauge(heat)
end
function HudUi:init()
fuelGauge = FuelGauge()
heatGauge = HeatGauge()
background = Background()
tos = TopOfScreen()
end
function HudUi:update()
HudUi.super.update(self)
self:collisions()
end
function HudUi:takeDamage()
for ticks = 1, 4 do
if ticks < 5 then
playdate.display.setInverted(ticks % 2)
playdate.wait(10)
end
end
end
function HudUi:collisions()
local collisions = tos:overlappingSprites()
if #collisions > 0 then
for c = 1, #collisions do
if collisions[c]:getTag() == 2 then -- rock
collisions[c].isCrushed = true
collisions[c]:remove()
end
end
end
end
I then add hudUI.lua to my main.lua inialize()
main.lua
local function initalize()
hudUi = HudUi(machine.isTakingDamage)
hudUi:add()
end
Ok phew we're over that now ^....^
I'm wanting all of my hud stuff to stay in my hudUI class. But the text belongs to the gauges, like fuel gauge and heat gauge. so I'm assuming I'd add the drawtext to those sprites. but when I do I still get nothing...
I feel like I've done every trick I can think of and am hitting a wall. Could someone help me clarify what the heck is going on?