Sprites.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // Copyright (c) 2008-2023 the Urho3D project
  2. // License: MIT
  3. #pragma once
  4. #include "Sample.h"
  5. /// Moving sprites example.
  6. /// This sample demonstrates:
  7. /// - Adding Sprite elements to the UI
  8. /// - Storing custom data (sprite velocity) inside UI elements
  9. /// - Handling frame update events in which the sprites are moved
  10. class Sprites : public Sample
  11. {
  12. // Enable type information.
  13. URHO3D_OBJECT(Sprites, Sample);
  14. public:
  15. /// Construct.
  16. explicit Sprites(Context* context);
  17. /// Setup after engine initialization and before running the main loop.
  18. void Start() override;
  19. protected:
  20. /// Return XML patch instructions for screen joystick layout for a specific sample app, if any.
  21. String GetScreenJoystickPatchString() const override { return
  22. "<patch>"
  23. " <add sel=\"/element/element[./attribute[@name='Name' and @value='Hat0']]\">"
  24. " <attribute name=\"Is Visible\" value=\"false\" />"
  25. " </add>"
  26. "</patch>";
  27. }
  28. private:
  29. /// Construct the sprites.
  30. void CreateSprites();
  31. /// Move the sprites using the delta time step given.
  32. void MoveSprites(float timeStep);
  33. /// Subscribe to application-wide logic update events.
  34. void SubscribeToEvents();
  35. /// Handle the logic update event.
  36. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  37. /// Vector to store the sprites for iterating through them.
  38. Vector<SharedPtr<Sprite>> sprites_;
  39. };