01_HelloWorld.lua 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. ExecuteFile("LuaScripts/Utilities/Sample.lua")
  2. HelloWorld = {}
  3. function HelloWorld:new()
  4. local o = {}
  5. self.__index = self
  6. setmetatable(o, self)
  7. setmetatable(self, {__index = Sample}) -- Set Sample as base class.
  8. return o
  9. end
  10. function HelloWorld:Start()
  11. Sample:Start() -- Call Start function in Sample.
  12. self:CreateText()
  13. end
  14. function HelloWorld:CreateText()
  15. local context = GetContext()
  16. local helloText = Text:new(context)
  17. helloText:SetText("Hello World from Urho3D!");
  18. local cache = GetCache()
  19. helloText:SetFont(cache:GetFont("Fonts/Anonymous Pro.ttf"), 30)
  20. helloText.color = Color(0.0, 1.0, 0.0)
  21. helloText.horizontalAlignment = HA_CENTER;
  22. helloText.verticalAlignment = VA_CENTER;
  23. GetUI():GetRoot():AddChild(helloText)
  24. end
  25. local sample = nil
  26. function Start()
  27. if sample == nil then
  28. sample = HelloWorld:new()
  29. end
  30. sample:Start()
  31. end
  32. function Stop()
  33. if sample ~= nil then
  34. sample:Stop()
  35. end
  36. sample = nil
  37. end