FloatingText Class Reference

#include <floating_text.hpp>

Inherits GameObject.

List of all members.

Public Member Functions

 FloatingText (const Vector &pos, const std::string &text_)
 FloatingText (const Vector &pos, int s)
virtual void update (float elapsed_time)
 This function is called once per frame and allows the object to update it's state.
virtual void draw (DrawingContext &context)
 The GameObject should draw itself onto the provided DrawingContext if this function is called.

Private Attributes

Vector position
std::string text
Timer timer

Static Private Attributes

static Color text_color


Detailed Description

Definition at line 29 of file floating_text.hpp.


Constructor & Destructor Documentation

FloatingText::FloatingText ( const Vector pos,
const std::string &  text_ 
)

Definition at line 24 of file floating_text.cpp.

References position, Timer::start(), text, timer, and Vector::x.

00024                                                                     :
00025   position(pos), 
00026   text(text_),
00027   timer()
00028 {
00029   timer.start(.1f);
00030   position.x -= text.size() * 8;
00031 }

FloatingText::FloatingText ( const Vector pos,
int  s 
)

Definition at line 33 of file floating_text.cpp.

References position, Timer::start(), text, timer, and Vector::x.

00033                                                        :
00034   position(pos),
00035   text(),
00036   timer()
00037 {
00038   timer.start(.1f);
00039 
00040   // turn int into a string
00041   char str[10];
00042   snprintf(str, 10, "%d", score);
00043   text = str;
00044 
00045   position.x -= text.size() * 8;
00046 }


Member Function Documentation

void FloatingText::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 49 of file floating_text.cpp.

References Timer::check(), position, GameObject::remove_me(), timer, and Vector::y.

00050 {
00051   position.y -= 1.4 * elapsed_time;
00052 
00053   if(timer.check())
00054     remove_me();
00055 }

void FloatingText::draw ( DrawingContext context  )  [virtual]

The GameObject should draw itself onto the provided DrawingContext if this function is called.

Implements GameObject.

Definition at line 60 of file floating_text.cpp.

References ALIGN_LEFT, DrawingContext::draw_text(), FADING_TIME, Timer::get_timeleft(), LAYER_OBJECTS, Resources::normal_font, DrawingContext::pop_transform(), position, DrawingContext::push_transform(), DrawingContext::set_alpha(), text, text_color, and timer.

00061 {
00062   // make an alpha animation when disappearing
00063   int alpha;
00064   if(timer.get_timeleft() < FADING_TIME)
00065     alpha = int(timer.get_timeleft() * 255 / FADING_TIME);
00066   else
00067     alpha = 255;
00068 
00069   context.push_transform();
00070   context.set_alpha(alpha);
00071 
00072   context.draw_text(Resources::normal_font, text, position, ALIGN_LEFT, LAYER_OBJECTS+1, FloatingText::text_color);
00073 
00074   context.pop_transform();
00075 }


Member Data Documentation

Color FloatingText::text_color [static, private]

Definition at line 31 of file floating_text.hpp.

Referenced by draw().

Vector FloatingText::position [private]

Definition at line 40 of file floating_text.hpp.

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

std::string FloatingText::text [private]

Definition at line 41 of file floating_text.hpp.

Referenced by draw(), and FloatingText().

Timer FloatingText::timer [private]

Definition at line 42 of file floating_text.hpp.

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


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