#include <floating_image.hpp>
Inherits GameObject.
Public Member Functions | |
FloatingImage (const std::string &sprite) | |
virtual | ~FloatingImage () |
void | set_layer (int layer) |
int | get_layer () const |
void | set_pos (const Vector &pos) |
const Vector & | get_pos () const |
void | set_anchor_point (AnchorPoint anchor) |
AnchorPoint | get_anchor_point () const |
void | set_visible (bool visible) |
bool | get_visible () const |
void | set_action (const std::string &action) |
std::string | get_action () |
void | fade_in (float fadetime) |
void | fade_out (float fadetime) |
void | update (float elapsed_time) |
This function is called once per frame and allows the object to update it's state. | |
void | draw (DrawingContext &context) |
The GameObject should draw itself onto the provided DrawingContext if this function is called. | |
Private Attributes | |
SpritePtr | sprite |
int | layer |
bool | visible |
AnchorPoint | anchor |
Vector | pos |
float | fading |
float | fadetime |
Definition at line 26 of file floating_image.hpp.
FloatingImage::FloatingImage | ( | const std::string & | sprite | ) |
Definition at line 22 of file floating_image.cpp.
00022 : 00023 sprite(sprite_manager->create(spritefile)), 00024 layer(LAYER_FOREGROUND1 + 1), 00025 visible(false), 00026 anchor(ANCHOR_MIDDLE), 00027 pos(), 00028 fading(0), 00029 fadetime(0) 00030 { 00031 }
FloatingImage::~FloatingImage | ( | ) | [virtual] |
void FloatingImage::set_layer | ( | int | layer | ) | [inline] |
int FloatingImage::get_layer | ( | ) | const [inline] |
Definition at line 36 of file floating_image.hpp.
References layer.
00036 { 00037 return layer; 00038 }
void FloatingImage::set_pos | ( | const Vector & | pos | ) | [inline] |
const Vector& FloatingImage::get_pos | ( | ) | const [inline] |
void FloatingImage::set_anchor_point | ( | AnchorPoint | anchor | ) | [inline] |
AnchorPoint FloatingImage::get_anchor_point | ( | ) | const [inline] |
Definition at line 50 of file floating_image.hpp.
References anchor.
00050 { 00051 return anchor; 00052 }
void FloatingImage::set_visible | ( | bool | visible | ) | [inline] |
bool FloatingImage::get_visible | ( | ) | const [inline] |
Definition at line 57 of file floating_image.hpp.
References visible.
00057 { 00058 return visible; 00059 }
void FloatingImage::set_action | ( | const std::string & | action | ) |
Definition at line 58 of file floating_image.cpp.
References sprite.
00059 { 00060 sprite->set_action(action); 00061 }
std::string FloatingImage::get_action | ( | ) |
Definition at line 64 of file floating_image.cpp.
References sprite.
00065 { 00066 return sprite->get_action(); 00067 }
void FloatingImage::fade_in | ( | float | fadetime | ) |
void FloatingImage::fade_out | ( | float | fadetime | ) |
void FloatingImage::update | ( | float | elapsed_time | ) | [virtual] |
This function is called once per frame and allows the object to update it's state.
The elapsed_time is the time since the last frame in seconds and should be the base for all timed calculations (don't use SDL_GetTicks directly as this will fail in pause mode)
Implements GameObject.
Definition at line 38 of file floating_image.cpp.
References fading, and visible.
00039 { 00040 if(fading > 0) { 00041 fading -= elapsed_time; 00042 if(fading <= 0) { 00043 fading = 0; 00044 visible = true; 00045 } 00046 } else if(fading < 0) { 00047 fading += elapsed_time; 00048 if(fading >= 0) { 00049 fading = 0; 00050 visible = false; 00051 } 00052 } 00053 00054 // (void) elapsed_time; 00055 }
void FloatingImage::draw | ( | DrawingContext & | context | ) | [virtual] |
The GameObject should draw itself onto the provided DrawingContext if this function is called.
Implements GameObject.
Definition at line 84 of file floating_image.cpp.
References anchor, fadetime, fading, get_anchor_pos(), layer, DrawingContext::pop_transform(), pos, DrawingContext::push_transform(), SCREEN_HEIGHT, SCREEN_WIDTH, DrawingContext::set_alpha(), DrawingContext::set_translation(), sprite, and visible.
00085 { 00086 context.push_transform(); 00087 context.set_translation(Vector(0, 0)); 00088 00089 if(fading > 0) { 00090 context.set_alpha((fadetime-fading) / fadetime); 00091 } else if(fading < 0) { 00092 context.set_alpha(-fading / fadetime); 00093 } else if(!visible) { 00094 context.pop_transform(); 00095 return; 00096 } 00097 00098 Vector spos = pos + get_anchor_pos(Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), 00099 sprite->get_width(), sprite->get_height(), anchor); 00100 00101 sprite->draw(context, spos, layer); 00102 00103 context.pop_transform(); 00104 }
SpritePtr FloatingImage::sprite [private] |
Definition at line 71 of file floating_image.hpp.
Referenced by draw(), get_action(), and set_action().
int FloatingImage::layer [private] |
bool FloatingImage::visible [private] |
Definition at line 73 of file floating_image.hpp.
Referenced by draw(), get_visible(), and update().
AnchorPoint FloatingImage::anchor [private] |
Vector FloatingImage::pos [private] |
float FloatingImage::fading [private] |
Definition at line 76 of file floating_image.hpp.
Referenced by draw(), fade_in(), fade_out(), and update().
float FloatingImage::fadetime [private] |