Jump to content

Absolute positioning of label

Recommended Posts


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

Here's what I have:


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
        if inst == _G.ThePlayer and not show_time then
        inst.GetMyDisplayName = function(inst)
            return inst:GetDisplayName()
        local label = inst.entity:AddLabel()
        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))
            ctime = os_module.date("*t")
                label:SetText(("%02d:%02d:%02d"):format(ctime.hour, ctime.min, ctime.sec))

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

  • Create New...