1933b9bd7c05da07f813d91a9a90b1a8c914a0d0
[supertux.git] / src / object / floating_image.cpp
1 #include <config.h>
2
3 #include <stdexcept>
4 #include "resources.hpp"
5 #include "main.hpp"
6 #include "math/rect.hpp"
7 #include "sprite/sprite_manager.hpp"
8 #include "sprite/sprite.hpp"
9 #include "video/drawing_context.hpp"
10 #include "lisp/lisp.hpp"
11 #include "floating_image.hpp"
12
13 FloatingImage::FloatingImage(const std::string& spritefile) 
14   : sprite(NULL), layer(LAYER_FOREGROUND1 + 1), visible(false),
15     anchor(ANCHOR_MIDDLE)
16 {
17   sprite = sprite_manager->create(spritefile);
18 }
19
20 FloatingImage::~FloatingImage()
21 {
22   delete sprite;
23 }
24
25 void
26 FloatingImage::update(float elapsed_time)
27 {
28   (void) elapsed_time;
29 }
30
31 void
32 FloatingImage::draw(DrawingContext& context)
33 {
34   if(!visible)
35     return;
36
37   context.push_transform();
38   context.set_translation(Vector(0, 0));
39
40   Vector spos = pos + get_anchor_pos(Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT),
41       sprite->get_width(), sprite->get_height(), anchor);
42
43   sprite->draw(context, spos, layer);
44
45   context.pop_transform();
46 }