Bromeon
Animation/Animator.hpp
Go to the documentation of this file.
00001 
00002 //
00003 // Thor C++ Library
00004 // Copyright (c) 2011-2012 Jan Haller
00005 // 
00006 // This software is provided 'as-is', without any express or implied
00007 // warranty. In no event will the authors be held liable for any damages
00008 // arising from the use of this software.
00009 // 
00010 // Permission is granted to anyone to use this software for any purpose,
00011 // including commercial applications, and to alter it and redistribute it
00012 // freely, subject to the following restrictions:
00013 // 
00014 // 1. The origin of this software must not be misrepresented; you must not
00015 //    claim that you wrote the original software. If you use this software
00016 //    in a product, an acknowledgment in the product documentation would be
00017 //    appreciated but is not required.
00018 // 
00019 // 2. Altered source versions must be plainly marked as such, and must not be
00020 //    misrepresented as being the original software.
00021 // 
00022 // 3. This notice may not be removed or altered from any source distribution.
00023 //
00025 
00028 
00029 #ifndef THOR_ANIMATOR_HPP
00030 #define THOR_ANIMATOR_HPP
00031 
00032 #include <Thor/Animation/Animation.hpp>
00033 #include <Thor/Config.hpp>
00034 
00035 #include <SFML/System/Time.hpp>
00036 #include <SFML/Graphics/Sprite.hpp>
00037 
00038 #include <map>
00039 #include <string>
00040 
00041 
00042 namespace thor
00043 {
00044 
00047 
00051 class THOR_API Animator
00052 {
00053     // ---------------------------------------------------------------------------------------------------------------------------
00054     // Public member functions
00055     public:
00058                                     Animator();
00059 
00064         void                        AddAnimation(const std::string& name, Animation::Ptr animation, sf::Time duration);
00065 
00069         void                        PlayAnimation(const std::string& name, bool loop = false);
00070 
00074         void                        StopAnimation();
00075 
00078         void                        Update(sf::Time dt);
00079 
00083         void                        Animate(sf::Sprite& target) const;
00084 
00090         void                        SetDefaultAnimation(Animation::Ptr animation, sf::Time duration);
00091 
00092 
00093     // ---------------------------------------------------------------------------------------------------------------------------
00094     // Private types
00095     private:
00096         typedef std::pair<Animation::Ptr, sf::Time>     ScaledAnimation;
00097         typedef std::map<std::string, ScaledAnimation>  AnimationMap;
00098 
00099 
00100     // ---------------------------------------------------------------------------------------------------------------------------
00101     // Private member functions
00102     private:
00103         void                        PlayAnimation(ScaledAnimation& animation, bool loop);
00104 
00105             
00106     // ---------------------------------------------------------------------------------------------------------------------------
00107     // Private variables
00108     private:
00109         AnimationMap                mAnimationMap;
00110         const ScaledAnimation*      mPlayingAnimation;
00111         ScaledAnimation             mDefaultAnimation;
00112         float                       mProgress;
00113         bool                        mLoop;
00114 };
00115 
00117 
00118 } // namespace thor
00119 
00120 #endif // THOR_ANIMATOR_HPP