User Interfaces

Drawing UI

Keeping On Screen

Label = {}
class("Label").extends(gfx.sprite)

function Label:init(text, x, y)
    Label.super.init(self)
    self:setText(text)
    self:setCenter(0, 0) -- Sets the center to the top left of the image
    self:moveTo(x, y)  -- Now the top left of the sprite (0, 0 == top left)
    self:add()  -- Don't for get to add!
    self:setIgnoresDrawOffset(true)  -- This will keep the sprite on screen
end

function Label:setText(text)
    -- Pass the screen size as the max for the imageWithText function
    local image = gfx.imageWithText(text, 400, 240)
    self:setImage(image)
end