01_HelloWorld.lua 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. -- Set the mouse mode to use in the sample
  13. SampleInitMouseMode(MM_FREE)
  14. -- Finally, hook-up this HelloWorld instance to handle update events
  15. SubscribeToEvents()
  16. end
  17. function CreateText()
  18. -- Construct new Text object
  19. local helloText = Text:new()
  20. -- Set String to display
  21. helloText.text = "Hello World from Urho3D!"
  22. -- Set font and text color
  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. ui.root:AddChild(helloText)
  30. end
  31. function SubscribeToEvents()
  32. -- Subscribe HandleUpdate() function for processing update events
  33. SubscribeToEvent("Update", "HandleUpdate")
  34. end
  35. function HandleUpdate(eventType, eventData)
  36. -- Do nothing for now, could be extended to eg. animate the display
  37. end
  38. -- Create XML patch instructions for screen joystick layout specific to this sample app
  39. function GetScreenJoystickPatchString()
  40. return
  41. "<patch>" ..
  42. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">" ..
  43. " <attribute name=\"Is Visible\" value=\"false\" />" ..
  44. " </add>" ..
  45. "</patch>"
  46. end