Urho2DSprite.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright (c) 2008-2022 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. namespace Urho3D
  6. {
  7. class Node;
  8. class Scene;
  9. }
  10. /// Urho2D sprite example.
  11. /// This sample demonstrates:
  12. /// - Creating a 2D scene with sprite
  13. /// - Displaying the scene using the Renderer subsystem
  14. /// - Handling keyboard to move and zoom 2D camera
  15. class Urho2DSprite : public Sample
  16. {
  17. URHO3D_OBJECT(Urho2DSprite, Sample);
  18. public:
  19. /// Construct.
  20. explicit Urho2DSprite(Context* context);
  21. /// Setup after engine initialization and before running the main loop.
  22. void Start() override;
  23. protected:
  24. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  25. String GetScreenJoystickPatchString() const override { return
  26. "<patch>"
  27. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/attribute[@name='Is Visible']\" />"
  28. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom In</replace>"
  29. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button0']]\">"
  30. " <element type=\"Text\">"
  31. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  32. " <attribute name=\"Text\" value=\"PAGEUP\" />"
  33. " </element>"
  34. " </add>"
  35. " <remove sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/attribute[@name='Is Visible']\" />"
  36. " <replace sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]/element[./attribute[@name='Name' and @value='Label']]/attribute[@name='Text']/@value\">Zoom Out</replace>"
  37. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Button1']]\">"
  38. " <element type=\"Text\">"
  39. " <attribute name=\"Name\" value=\"KeyBinding\" />"
  40. " <attribute name=\"Text\" value=\"PAGEDOWN\" />"
  41. " </element>"
  42. " </add>"
  43. "</patch>";
  44. }
  45. private:
  46. /// Construct the scene content.
  47. void CreateScene();
  48. /// Construct an instruction text to the UI.
  49. void CreateInstructions();
  50. /// Set up a viewport for displaying the scene.
  51. void SetupViewport();
  52. /// Read input and moves the camera.
  53. void MoveCamera(float timeStep);
  54. /// Subscribe to application-wide logic update events.
  55. void SubscribeToEvents();
  56. /// Handle the logic update event.
  57. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  58. /// Sprite nodes.
  59. Vector<SharedPtr<Node>> spriteNodes_;
  60. };