@@ -165,15 +165,46 @@ void animationManager::Tick()
165165 const double remainder = fmod (val, mod);
166166 return remainder < 0 ? remainder + mod : remainder;
167167 };
168- this ->CurrentTime = this ->TimeRange [0 ] +
169- modulo (this ->CurrentTime - this ->TimeRange [0 ], this ->TimeRange [1 ] - this ->TimeRange [0 ]);
168+
169+ // Switching between animation modes, forward is default
170+ switch (this ->AnimationMode )
171+ {
172+ case AnimationModeType::PINGPONG :
173+ this ->AnimationDirection *= -1 ;
174+ if (this ->CurrentTime < this ->TimeRange [0 ])
175+ {
176+ this ->CurrentTime = this ->TimeRange [0 ] + (this ->TimeRange [0 ] - this ->CurrentTime );
177+ }
178+ else if (this ->CurrentTime > this ->TimeRange [1 ])
179+ {
180+ this ->CurrentTime = this ->TimeRange [1 ] - (this ->CurrentTime - this ->TimeRange [1 ]);
181+ }
182+ break ;
183+ case AnimationModeType::BACKWARD :
184+ this ->AnimationDirection = -1 ;
185+ this ->CurrentTime = this ->TimeRange [0 ] +
186+ modulo (this ->CurrentTime - this ->TimeRange [0 ], this ->TimeRange [1 ] - this ->TimeRange [0 ]);
187+ default :
188+ this ->AnimationDirection = 1 ;
189+ this ->CurrentTime = this ->TimeRange [0 ] +
190+ modulo (this ->CurrentTime - this ->TimeRange [0 ], this ->TimeRange [1 ] - this ->TimeRange [0 ]);
191+ break ;
192+ }
193+ if (this ->AnimationMaxRepeat != -1 )
194+ {
195+ this ->AnimationCurrentRepeat ++;
196+ }
170197 }
171198
172199 if (this ->LoadAtTime (this ->CurrentTime ))
173200 {
174201 this ->Window .render ();
175202 }
176203 }
204+ if (this ->AnimationMaxRepeat != -1 && this ->AnimationCurrentRepeat == this ->AnimationMaxRepeat )
205+ {
206+ this ->Playing = false ;
207+ }
177208}
178209
179210// ----------------------------------------------------------------------------
@@ -692,10 +723,39 @@ void animationManager::SetAnimationDirection(int direction)
692723 this ->AnimationDirection = direction;
693724}
694725
726+ // ----------------------------------------------------------------------------
727+ void animationManager::SetAnimationMode (const std::string& mode)
728+ {
729+ if (mode == " backward" )
730+ {
731+ this ->AnimationMode = AnimationModeType::BACKWARD ;
732+ this ->AnimationDirection = -1 ;
733+ }
734+ else if (mode == " pingpong" )
735+ {
736+ this ->AnimationMode = AnimationModeType::PINGPONG ;
737+ this ->AnimationDirection = 1 ;
738+ }
739+ else
740+ {
741+ this ->AnimationMode = AnimationModeType::FORWARD ;
742+ this ->AnimationDirection = 1 ;
743+ }
744+ }
745+
746+ // ----------------------------------------------------------------------------
747+ void animationManager::SetAnimationRepeat (int repeat)
748+ {
749+ assert (repeat >= -1 );
750+ this ->AnimationMaxRepeat = repeat;
751+ }
752+
695753// ----------------------------------------------------------------------------
696754void animationManager::UpdateDynamicOptions ()
697755{
698756 this ->SetAutoplay (this ->Options .scene .animation .autoplay );
699757 this ->SetSpeedFactor (this ->Options .scene .animation .speed_factor );
758+ this ->SetAnimationMode (this ->Options .scene .animation .mode );
759+ this ->SetAnimationRepeat (this ->Options .scene .animation .repeat );
700760}
701761}
0 commit comments