2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "object/floating_image.hpp"
18 #include "sprite/sprite.hpp"
19 #include "sprite/sprite_manager.hpp"
20 #include "supertux/globals.hpp"
22 FloatingImage::FloatingImage(const std::string& spritefile) :
23 sprite(sprite_manager->create(spritefile)),
24 layer(LAYER_FOREGROUND1 + 1),
26 anchor(ANCHOR_MIDDLE),
33 FloatingImage::~FloatingImage()
38 FloatingImage::update(float elapsed_time)
41 fading -= elapsed_time;
46 } else if(fading < 0) {
47 fading += elapsed_time;
54 // (void) elapsed_time;
58 FloatingImage::set_action(const std::string& action)
60 sprite->set_action(action);
64 FloatingImage::get_action()
66 return sprite->get_action();
70 FloatingImage::fade_in(float fadetime)
72 this->fadetime = fadetime;
77 FloatingImage::fade_out(float fadetime)
79 this->fadetime = fadetime;
84 FloatingImage::draw(DrawingContext& context)
86 context.push_transform();
87 context.set_translation(Vector(0, 0));
90 context.set_alpha((fadetime-fading) / fadetime);
91 } else if(fading < 0) {
92 context.set_alpha(-fading / fadetime);
94 context.pop_transform();
98 Vector spos = pos + get_anchor_pos(Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
99 sprite->get_width(), sprite->get_height(), anchor);
101 sprite->draw(context, spos, layer);
103 context.pop_transform();