I'm running the latest sdk on linux and having an issue where I can't fill a rect properly. I set pd.display.setInverted(true)
, so everything is inverted.
In order to display white UI text over a filled black rect, I'm trying:
function createBackground(x, y, width, height)
backgroundSprite = gfx.sprite.new()
local backgroundImage = gfx.image.new(width, height)
gfx.pushContext(backgroundImage)
gfx.setColor(gfx.kColorWhite)
gfx.fillRect(0, 0, width, height)
gfx.popContext()
backgroundSprite:setImage(backgroundImage)
backgroundSprite:setCenter(0, 0)
backgroundSprite:moveTo(x, y)
backgroundSprite:add()
end
However, I don't see anything. If I update the code to gfx.setColor(gfx.kColorBlack)
, I get a white filled rect over my black background, but I want a black filled rect over a black background for drawing UI elements on top of.
I'm calling the above code from this code:
function createScoreDisplay(x, y)
scoreSprite = gfx.sprite.new()
updateScoreDisplay()
scoreSprite:setCenter(0, 0)
scoreSprite:moveTo(x, y)
scoreSpriteWidth, scoreSpriteHeight = scoreSprite:getSize()
createBackground(x, y, scoreSpriteWidth, scoreSpriteHeight)
scoreSprite:add()
end
function updateScoreDisplay()
gfx.setFont(uiFont)
local scoreText = "Score: " .. score
local textWidth, textHeight = gfx.getTextSize(scoreText)
local scoreImage = gfx.image.new(textWidth + (uiOffsetX * 2), textHeight + (uiOffsetY * 2))
gfx.pushContext(scoreImage)
gfx.drawText(scoreText, uiOffsetX, uiOffsetY)
gfx.popContext()
scoreSprite:setImage(scoreImage)
end
Any ideas why this isn't working?