AnimatedSprite.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_ANIMATED_SPRITE_HPP
30 #define NOMLIB_ANIMATED_SPRITE_HPP
31 
32 #include <iostream>
33 #include <string>
34 
35 #include "SDL.h"
36 
37 #include "nomlib/config.hpp"
38 #include "nomlib/graphics/sprite/SpriteBatch.hpp"
39 #include "nomlib/system/AnimationTimer.hpp"
40 
41 //#define NOM_DEBUG_ANIMATED_SPRITE
42 
43 namespace nom {
44 
46  public SpriteBatch
47 {
48  public:
49  enum AnimationStyle
50  {
51  NoStyle = 0,
52  Blink,
53  Oscillate
54  };
55 
56  enum AnimationStatus
57  {
58  Stopped = 0,
59  Playing,
60  Paused
61  };
62 
65  AnimatedSprite ( void );
66 
69  AnimatedSprite ( const SpriteSheet& sheet );
70 
73  AnimatedSprite ( const std::string& filename );
74 
76  virtual ~AnimatedSprite ( void );
77 
79  int32 total_frames ( void ) const;
80 
82  int32 frame_inc ( void ) const;
83 
85  int32 frame ( void ) const;
86 
88  AnimatedSprite::AnimationStyle style ( void ) const;
89 
91  AnimatedSprite::AnimationStatus status ( void ) const;
92 
96  void setFrameRate ( int32 rate );
97 
102  void setCurrentFrame ( int32 frame );
103 
105  void setAnimationStyle ( AnimatedSprite::AnimationStyle style );
106 
108  void play ( void );
109 
111  void stop ( void );
112 
114  void pause ( void );
115 
117  void unpause ( void );
118 
119  protected:
121  void update_animation ( void );
122 
124  void initialize ( void );
125 
127  void setMaxFrames ( int32 max );
128 
130  void setFrameIncrement ( int32 increment );
131 
133  void setAnimationStatus ( AnimatedSprite::AnimationStatus status );
134 
136  int32 max_frames;
137 
140 
143 
145  enum AnimatedSprite::AnimationStyle animation_style;
146 
148  enum AnimatedSprite::AnimationStatus animation_status;
149 
152 };
153 
154 
155 } // namespace nom
156 
157 #endif // include guard defined
void initialize(void)
Initialize values to their respective defaults.
Extended bitmap object rendering – utilizes sprite sheets.
Definition: SpriteBatch.hpp:44
void play(void)
Play the animation.
virtual ~AnimatedSprite(void)
Destructor.
int32 max_frames
Total number of animation frames.
int32 frame_inc(void) const
Get the frame increment value of this object.
AnimatedSprite::AnimationStatus status(void) const
Get the current status of this animation.
void unpause(void)
Un-pause the animation playback.
void setMaxFrames(int32 max)
Set the total number of animated frames for this object.
void setCurrentFrame(int32 frame)
int32 total_frames(void) const
Get the maximum number of animation frames for this object.
int32 current_frame
Current animation frame.
void update_animation(void)
Updates the playback of the animation.
enum AnimatedSprite::AnimationStatus animation_status
Status info.
AnimationTimer fps
Keeps record of our current tick and frame rate (think: frame delay)
int32 frame(void) const
Get the current frame of this object.
void setAnimationStatus(AnimatedSprite::AnimationStatus status)
Set a new status state for this object.
Specialized class container for the creation of sprite sheets via RFC 4627 JSON-compliant file input...
Definition: SpriteSheet.hpp:62
void setAnimationStyle(AnimatedSprite::AnimationStyle style)
Set a new style of animation for this object.
enum AnimatedSprite::AnimationStyle animation_style
Animation playback logic.
void setFrameRate(int32 rate)
void setFrameIncrement(int32 increment)
Set the increment value of each animated frame of this object.
AnimatedSprite::AnimationStyle style(void) const
Get the current animation style for this object.
int32 frame_increment
Value that we increment the current_frame by.
void pause(void)
Pause the animation playback.
void stop(void)
Stop the animation playback.