src/object/floating_image.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "object/floating_image.hpp"
00018 #include "sprite/sprite.hpp"
00019 #include "sprite/sprite_manager.hpp"
00020 #include "supertux/globals.hpp"
00021 
00022 FloatingImage::FloatingImage(const std::string& spritefile) :
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 }
00032 
00033 FloatingImage::~FloatingImage()
00034 {
00035 }
00036 
00037 void
00038 FloatingImage::update(float elapsed_time)
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 }
00056 
00057 void
00058 FloatingImage::set_action(const std::string& action)
00059 {
00060   sprite->set_action(action);
00061 }
00062 
00063 std::string
00064 FloatingImage::get_action()
00065 {
00066   return sprite->get_action();
00067 }
00068 
00069 void
00070 FloatingImage::fade_in(float fadetime)
00071 {
00072   this->fadetime = fadetime;
00073   fading = fadetime;
00074 }
00075 
00076 void
00077 FloatingImage::fade_out(float fadetime)
00078 {
00079   this->fadetime = fadetime;
00080   fading = -fadetime;
00081 }
00082 
00083 void
00084 FloatingImage::draw(DrawingContext& context)
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 }
00105 
00106 /* EOF */

Generated on Mon Jun 9 03:38:19 2014 for SuperTux by  doxygen 1.5.1