Jump to content

Absolute positioning of label


Recommended Posts

Hi,

I'm trying to position a label at (SCREEN_WIDTH/2, SCREEN_HEIGHT) coordinates on the screen.

Here's what I have:

Quote

GLOBAL.CHEATS_ENABLED = true
GLOBAL.require( 'debugkeys' )

os_module = GLOBAL.require "os" --thx ultroman
modimport "lib_ver.lua"

local show_time = GetModConfigData("show_time")

if not TUNING.SHOW_TIME then
    TUNING.SHOW_TIME = true
    AddPlayersAfterInit(function(inst)
        if inst == _G.ThePlayer and not show_time then
            return
        end
        inst.GetMyDisplayName = function(inst)
            return inst:GetDisplayName()
        end
        local label = inst.entity:AddLabel()
       
        label:SetFontSize(18)         
        label:SetFont(_G.BODYTEXTFONT)
        label:SetPosition(20, 0, 0)  --ERROR ('SetPosition' is nil)
        --label:SetUIOffset(0, 0, 0)
        ctime = os_module.date("*t")
        label:SetText(("%02d:%02d:%02d"):format(ctime.hour, ctime.min, ctime.sec))
        label:SetColour(255/255,255/255,255/255)
        label:Enable(true)
        inst:DoPeriodicTask(1,function()
            ctime = os_module.date("*t")
                label:SetText(("%02d:%02d:%02d"):format(ctime.hour, ctime.min, ctime.sec))
        end)
    end)
end
 

I have a few questions:

  1. Is label creation and the rest acceptable under AddPlayersAfterInit()? Or is there a different function/event hook for when the player is spawned? (I'm doing this as client-only)
  2. What's wrong with my usage of SetPosition()? Is it accessible from a different object/scope?
  3. Is there any documentation apart from http://dontstarveapi.com/?s=label ? For now, I grep through the scripts in the mods dir.

FWIW, it works partly when I replace SetPosition with SetWorldOffset but that's not what I want...(label moves with player)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...