Skip to content

Polycode User's FAQ

celeron55 edited this page Sep 21, 2014 · 6 revisions

How to combine C++ and Lua?

Basically by making a custom version of the Polycode Player.

How to get just something show up on the screen?

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)

How to get click events on buttons?

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)

My UI theme is screwed up with parts of it upside down; WTF?

There is a thing called Scene.SCENE_2D_TOPLEFT that you should use with UI.

How to set font size for UI elements?

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").

Clone this wiki locally