// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <cmath>
+#include <math.h>
#include "sprite/sprite.hpp"
#include "supertux/timer.hpp"
{
}
+SpritePtr
+Sprite::clone() const
+{
+ return SpritePtr(new Sprite(*this));
+}
+
void
Sprite::set_action(const std::string& name, int loops)
{
if(action && action->name == name)
return;
- SpriteData::Action* newaction = data.get_action(name);
+ const SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
log_debug << "Action '" << name << "' not found." << std::endl;
return;
if(action && action->name == name)
return;
- SpriteData::Action* newaction = data.get_action(name);
+ const SpriteData::Action* newaction = data.get_action(name);
if(!newaction) {
log_debug << "Action '" << name << "' not found." << std::endl;
return;
int frameidx = (int) frame;
if(frameidx >= get_frames() || frameidx < 0) {
-#ifndef DEBUG
+#ifdef NDEBUG
// in optimized mode we get some small rounding errors in floating point
// number sometimes...
log_warning << "frame out of range: " << frameidx << "/" << get_frames() << " at sprite: " << get_name() << "/" << get_action() << std::endl;
int
Sprite::get_width() const
{
- return (int) action->surfaces[get_frame()]->get_width();
+ if((int)frame >= get_frames() || (int)frame < 0)
+ {
+ log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ return 0;
+ }
+ else
+ {
+ return (int) action->surfaces[get_frame()]->get_width();
+ }
}
int
Sprite::get_height() const
{
+ if((int)frame >= get_frames() || (int)frame < 0)
+ {
+ log_warning << "frame out of range: " << (int)frame << "/" << get_frames() << " at " << get_name() << "/" << get_action() << std::endl;
+ return 0;
+ }
+ else
+ {
return (int) action->surfaces[get_frame()]->get_height();
+ }
}
float
return action->hitbox_h;
}
-Rect
+Rectf
Sprite::get_current_hitbox() const
{
- return Rect(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
-}
-
-void
-Sprite::set_fps(float new_fps)
-{
- action->fps = new_fps;
+ return Rectf(action->x_offset, action->y_offset, action->x_offset + action->hitbox_w, action->y_offset + action->hitbox_h);
}
void