01_HelloWorld.as 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. #include "Scripts/Utilities/Sample.as"
  7. void Start()
  8. {
  9. // Execute the common startup for samples
  10. SampleStart();
  11. // Create "Hello World" Text
  12. CreateText();
  13. // Finally, hook-up this HelloWorld instance to handle update events
  14. SubscribeToEvents();
  15. }
  16. void CreateText()
  17. {
  18. // Construct new Text object
  19. Text@ helloText = Text();
  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.0f, 1.0f, 0.0f);
  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. }
  31. void SubscribeToEvents()
  32. {
  33. // Subscribe HandleUpdate() function for processing update events
  34. SubscribeToEvent("Update", "HandleUpdate");
  35. }
  36. void HandleUpdate(StringHash eventType, VariantMap& eventData)
  37. {
  38. // Do nothing for now, could be extended to eg. animate the display
  39. }