-
Notifications
You must be signed in to change notification settings - Fork 349
Polycode User's FAQ
Basically by making a custom version of the Polycode Player or if you want to write the main application in Lua write a Polycode module and use it from Lua.
Lua (Note: You need to make sure you have a font loaded for this to work; the IDE/Player will load one automatically):
scene = Scene(Scene.SCENE_2D)
scene:getActiveCamera():setOrthoSize(640, 480)
label = SceneLabel("Hello from Lua!", 32)
label:setPosition(-50, -50, 0)
scene:addChild(label)
One likely cause is that you add something to the scene or some other entity, but don't store a reference to it in a persistent location. The asiest way to get started is to just store entities in global variables, or make a global table for them.
You have to set processInputEvents = true
for each entity from the root to the top.
Lua: Start with scene.rootEntity.processInputEvents = true
, then do something like:
button = UIButton("Button", 100, 50)
button:setPosition(100, -100)
scene:addEntity(button)
class "Thing" (EventHandler)
function Thing:Thing()
EventHandler.EventHandler(self)
end
function Thing:on_click_event(e)
print("Thing:on_click_event()")
end
thing = Thing()
button:addEventListener(thing, Thing.on_click_event, UIEvent.CLICK_EVENT)
There is a thing called Scene.SCENE_2D_TOPLEFT
that you should use with UI.
Lua, for buttons:
CoreServices.getInstance():getConfig():setNumericValue("Polycode", "uiButtonFontSize", 30)
In most cases it is probably best practice to use the .xml configuration file for these; see eg. UIThemes/dark/theme.xml
. You can load those with CoreServices.getInstance():getConfig():loadConfig("Polycode", "path/to/Assets/UIThemes/dark/theme.xml")
.
Also, there are references to image files in theme.xml. You can set the base path for those this way: CoreServices.getInstance():getResourceManager():addArchive("path/to/Assets");