00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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