01_HelloWorld.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 helloText = Text:new()
  18. -- Set String to display
  19. helloText.text = "Hello World from Urho3D!"
  20. -- Set font and text color
  21. helloText:SetFont(cache:GetResource("Font", "Fonts/Anonymous Pro.ttf"), 30)
  22. helloText.color = Color(0.0, 1.0, 0.0)
  23. -- Align Text center-screen
  24. helloText.horizontalAlignment = HA_CENTER
  25. helloText.verticalAlignment = VA_CENTER
  26. -- Add Text instance to the UI root element
  27. ui.root:AddChild(helloText)
  28. end
  29. function SubscribeToEvents()
  30. -- Subscribe HandleUpdate() function for processing update events
  31. SubscribeToEvent("Update", "HandleUpdate")
  32. end
  33. function HandleUpdate(eventType, eventData)
  34. -- Do nothing for now, could be extended to eg. animate the display
  35. end
  36. -- Create XML patch instructions for screen joystick layout specific to this sample app
  37. function GetScreenJoystickPatchString()
  38. return
  39. "<patch>" ..
  40. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">" ..
  41. " <attribute name=\"Is Visible\" value=\"false\" />" ..
  42. " </add>" ..
  43. "</patch>"
  44. end