diff --git a/src/mover.hpp b/src/mover.hpp index 2dd1f1a..ae14cfa 100644 --- a/src/mover.hpp +++ b/src/mover.hpp @@ -14,7 +14,7 @@ namespace cloonel { Mover ( void ) = default; virtual ~Mover ( void ) noexcept = default; - void Update ( float parDelta ); + virtual void Update ( float parDelta ); PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable ) { return m_placeables.Add(parPlaceable); } void UnregisterPlaceable ( PlaceableTicketType parID ) noexcept { m_placeables.Remove(parID); } diff --git a/src/moverrelative.cpp b/src/moverrelative.cpp index be21b0f..0bcf034 100644 --- a/src/moverrelative.cpp +++ b/src/moverrelative.cpp @@ -2,10 +2,24 @@ #include "placeable.hpp" namespace cloonel { + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + MoverRelative::MoverRelative() : + m_prevOffset(0.0f) + { + } + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void MoverRelative::UpdateSingle (Placeable* parPlaceable) { - const float2 newPos(GetOffset() - parPlaceable->GetPos()); - parPlaceable->AddOffset(newPos); + const float2 offs(GetOffset() - m_prevOffset); + parPlaceable->AddOffset(offs); + } + + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + void MoverRelative::Update (float parDelta) { + m_prevOffset = GetOffset(); + Mover::Update(parDelta); } } //namespace cloonel diff --git a/src/moverrelative.hpp b/src/moverrelative.hpp index cb3642d..8766f87 100644 --- a/src/moverrelative.hpp +++ b/src/moverrelative.hpp @@ -6,12 +6,17 @@ namespace cloonel { class MoverRelative : public Mover { public: - MoverRelative ( void ) = default; + MoverRelative ( void ); virtual ~MoverRelative ( void ) noexcept = default; + virtual void Update ( float parDelta ); + protected: virtual void UpdateSingle ( Placeable* parPlaceable ); virtual float2 GetOffset ( void ) const = 0; + + private: + float2 m_prevOffset; }; } //namespace cloonel