projects
/
supertux.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Unified Messaging Subsystem
[supertux.git]
/
src
/
sprite
/
sprite.cpp
diff --git
a/src/sprite/sprite.cpp
b/src/sprite/sprite.cpp
index
28dc1fa
..
1c8d0bf
100644
(file)
--- a/
src/sprite/sprite.cpp
+++ b/
src/sprite/sprite.cpp
@@
-23,8
+23,9
@@
#include <cassert>
#include <stdexcept>
#include <cassert>
#include <stdexcept>
-#include "sprite.h"
-#include "video/drawing_context.h"
+#include "sprite.hpp"
+#include "video/drawing_context.hpp"
+#include "msg.hpp"
Sprite::Sprite(SpriteData& newdata)
: data(newdata), frame(0), animation_loops(-1)
Sprite::Sprite(SpriteData& newdata)
: data(newdata), frame(0), animation_loops(-1)
@@
-48,16
+49,14
@@
Sprite::~Sprite()
}
void
}
void
-Sprite::set_action(
std::string
name, int loops)
+Sprite::set_action(
const std::string&
name, int loops)
{
if(action && action->name == name)
return;
SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
{
if(action && action->name == name)
return;
SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
-#ifdef DEBUG
- std::cerr << "Action '" << name << "' not found.\n";
-#endif
+ msg_debug("Action '" << name << "' not found.");
return;
}
return;
}
@@
-67,7
+66,7
@@
Sprite::set_action(std::string name, int loops)
}
bool
}
bool
-Sprite::
check_animation
()
+Sprite::
animation_done
()
{
return animation_loops == 0;
}
{
return animation_loops == 0;
}
@@
-75,7
+74,7
@@
Sprite::check_animation()
void
Sprite::update()
{
void
Sprite::update()
{
- if(animation_
loops == 0
)
+ if(animation_
done()
)
return;
Uint32 ticks = SDL_GetTicks();
return;
Uint32 ticks = SDL_GetTicks();
@@
-85,58
+84,63
@@
Sprite::update()
frame += frame_inc;
if(frame >= get_frames()) {
frame += frame_inc;
if(frame >= get_frames()) {
- frame = fmodf(frame
+get_frames()
, get_frames());
-
+ frame = fmodf(frame, get_frames());
+
animation_loops--;
animation_loops--;
- if(animation_
loops == 0
)
- frame =
0
;
+ if(animation_
done()
)
+ frame =
get_frames()-1
;
}
}
void
}
}
void
-Sprite::draw(DrawingContext& context, const Vector& pos, int layer,
- Uint32 drawing_effect)
+Sprite::draw(DrawingContext& context, const Vector& pos, int layer)
{
assert(action != 0);
update();
if((int)frame >= get_frames() || (int)frame < 0)
{
assert(action != 0);
update();
if((int)frame >= get_frames() || (int)frame < 0)
-
std::cerr << "Warning:
frame out of range: " << (int)frame
+
msg_warning("
frame out of range: " << (int)frame
<< "/" << get_frames() << " at " << get_name()
<< "/" << get_frames() << " at " << get_name()
- << "/" << get_action_name()
<< std::endl
;
+ << "/" << get_action_name()
)
;
else
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
else
context.draw_surface(action->surfaces[(int)frame],
pos - Vector(action->x_offset, action->y_offset),
- layer + action->z_order
, drawing_effect
);
+ layer + action->z_order);
}
void
Sprite::draw_part(DrawingContext& context, const Vector& source,
}
void
Sprite::draw_part(DrawingContext& context, const Vector& source,
- const Vector& size, const Vector& pos, int layer
, Uint32 drawing_effect
)
+ const Vector& size, const Vector& pos, int layer)
{
assert(action != 0);
update();
if((int)frame >= get_frames() || (int)frame < 0)
{
assert(action != 0);
update();
if((int)frame >= get_frames() || (int)frame < 0)
-
std::cerr << "Warning:
frame out of range: " << (int)frame
+
msg_warning("
frame out of range: " << (int)frame
<< "/" << get_frames() << " at sprite: " << get_name()
<< "/" << get_frames() << " at sprite: " << get_name()
- << "/" << get_action_name()
<< std::endl
;
+ << "/" << get_action_name()
)
;
else
context.draw_surface_part(action->surfaces[(int)frame], source, size,
pos - Vector(action->x_offset, action->y_offset),
else
context.draw_surface_part(action->surfaces[(int)frame], source, size,
pos - Vector(action->x_offset, action->y_offset),
- layer + action->z_order
, drawing_effect
);
+ layer + action->z_order);
}
int
Sprite::get_width() const
{
}
int
Sprite::get_width() const
{
- return
action->surfaces[get_frame()]->w
;
+ return
(int) action->surfaces[get_frame()]->get_width()
;
}
int
Sprite::get_height() const
{
}
int
Sprite::get_height() const
{
- return action->surfaces[get_frame()]->h;
+ return (int) action->surfaces[get_frame()]->get_height();
+}
+
+void
+Sprite::set_fps(float new_fps)
+{
+ action->fps = new_fps;
}
}