01_HelloWorld.lua 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. -- This first example, maintaining tradition, prints a "Hello World" message.
  2. -- Furthermore it shows:
  3. -- - Using the Sample utility functions as a base for the application
  4. -- - Adding a Text element to the graphical user interface
  5. -- - Subscribing to and handling of update events
  6. require "LuaScripts/Utilities/Sample"
  7. function Start()
  8. -- Execute the common startup for samples
  9. SampleStart()
  10. -- Create "Hello World" Text
  11. CreateText()
  12. -- Finally, hook-up this HelloWorld instance to handle update events
  13. SubscribeToEvents()
  14. end
  15. function CreateText()
  16. -- Construct new Text object
  17. local context = GetContext()
  18. local helloText = Text:new(context)
  19. -- Set String to display
  20. helloText.text = "Hello World from Urho3D!"
  21. -- Set font and text color
  22. local cache = GetCache()
  23. helloText:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 30)
  24. helloText.color = Color(0.0, 1.0, 0.0)
  25. -- Align Text center-screen
  26. helloText.horizontalAlignment = HA_CENTER;
  27. helloText.verticalAlignment = VA_CENTER;
  28. -- Add Text instance to the UI root element
  29. local ui = GetUI()
  30. ui.root:AddChild(helloText)
  31. end
  32. function SubscribeToEvents()
  33. -- Subscribe HandleUpdate() function for processing update events
  34. SubscribeToEvent("Update", "HandleUpdate")
  35. end
  36. function HandleUpdate(eventType, eventData)
  37. -- Do nothing for now, could be extended to eg. animate the display
  38. end