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) :
24 layer(LAYER_FOREGROUND1 + 1),
26 anchor(ANCHOR_MIDDLE),
31 sprite = sprite_manager->create(spritefile);
34 FloatingImage::~FloatingImage()
39 FloatingImage::update(float elapsed_time)
42 fading -= elapsed_time;
47 } else if(fading < 0) {
48 fading += elapsed_time;
55 // (void) elapsed_time;
59 FloatingImage::set_action(const std::string& action)
61 sprite->set_action(action);
65 FloatingImage::get_action()
67 return sprite->get_action();
71 FloatingImage::fade_in(float fadetime)
73 this->fadetime = fadetime;
78 FloatingImage::fade_out(float fadetime)
80 this->fadetime = fadetime;
85 FloatingImage::draw(DrawingContext& context)
87 context.push_transform();
88 context.set_translation(Vector(0, 0));
91 context.set_alpha((fadetime-fading) / fadetime);
92 } else if(fading < 0) {
93 context.set_alpha(-fading / fadetime);
95 context.pop_transform();
99 Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
100 sprite->get_width(), sprite->get_height(), anchor);
102 sprite->draw(context, spos, layer);
104 context.pop_transform();