FloatingImage Class Reference

#include <floating_image.hpp>

Inherits GameObject.

List of all members.

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 Vectorget_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


Detailed Description

Definition at line 26 of file floating_image.hpp.


Constructor & Destructor Documentation

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]

Definition at line 33 of file floating_image.cpp.

00034 {
00035 }


Member Function Documentation

void FloatingImage::set_layer ( int  layer  )  [inline]

Definition at line 32 of file floating_image.hpp.

00032                             {
00033     this->layer = layer;
00034   }

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]

Definition at line 40 of file floating_image.hpp.

References pos.

00040                                   {
00041     this->pos = pos;
00042   }

const Vector& FloatingImage::get_pos (  )  const [inline]

Definition at line 43 of file floating_image.hpp.

References pos.

00043                                 {
00044     return pos;
00045   }

void FloatingImage::set_anchor_point ( AnchorPoint  anchor  )  [inline]

Definition at line 47 of file floating_image.hpp.

00047                                             {
00048     this->anchor = anchor;
00049   }

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]

Definition at line 54 of file floating_image.hpp.

00054                                  {
00055     this->visible = visible;
00056   }

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  ) 

Definition at line 70 of file floating_image.cpp.

References fading.

00071 {
00072   this->fadetime = fadetime;
00073   fading = fadetime;
00074 }

void FloatingImage::fade_out ( float  fadetime  ) 

Definition at line 77 of file floating_image.cpp.

References fading.

00078 {
00079   this->fadetime = fadetime;
00080   fading = -fadetime;
00081 }

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 }


Member Data Documentation

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]

Definition at line 72 of file floating_image.hpp.

Referenced by draw(), and get_layer().

bool FloatingImage::visible [private]

Definition at line 73 of file floating_image.hpp.

Referenced by draw(), get_visible(), and update().

AnchorPoint FloatingImage::anchor [private]

Definition at line 74 of file floating_image.hpp.

Referenced by draw(), and get_anchor_point().

Vector FloatingImage::pos [private]

Definition at line 75 of file floating_image.hpp.

Referenced by draw(), get_pos(), and set_pos().

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]

Definition at line 77 of file floating_image.hpp.

Referenced by draw().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:30 2014 for SuperTux by  doxygen 1.5.1