SDLPP: animation/movement chagnes
This commit is contained in:
@@ -13,7 +13,7 @@ void RenderObject::render() {
|
||||
polygon->render( *renderer );
|
||||
if ( texture != NULL ) {
|
||||
SDL_Rect *src = NULL;
|
||||
if ( animation.empty() ) {
|
||||
if ( animation.empty() || !animating ) {
|
||||
if ( !entireTexture() )
|
||||
src = &src_rect;
|
||||
} else {
|
||||
@@ -99,9 +99,15 @@ void RenderObject::unsetColor() {
|
||||
void RenderObject::setMovementSpeed( double speed ) {
|
||||
movementSpeed = speed;
|
||||
}
|
||||
void RenderObject::addMovement( int x, int y ) {
|
||||
void RenderObject::addMovement( double x, double y ) {
|
||||
movementDirection += { x, y };
|
||||
}
|
||||
void RenderObject::setMovement( double x, double y ) {
|
||||
movementDirection = { x, y };
|
||||
}
|
||||
Vec2D<double> RenderObject::getMovement() {
|
||||
return movementDirection;
|
||||
}
|
||||
void RenderObject::resetMovementX() {
|
||||
movementDirection = { 0, movementDirection.getY() };
|
||||
}
|
||||
@@ -146,7 +152,7 @@ void RenderObject::animate( int ticks ) {
|
||||
if ( animation_next_frame <= 0 ) {
|
||||
animation_index = ( animation_index + 1 ) % animation.size();
|
||||
animation_next_frame =
|
||||
( 1000 / animation_fps ) + animation_next_frame;
|
||||
animation_next_frame_base + animation_next_frame;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -154,12 +160,8 @@ void RenderObject::animate( int ticks ) {
|
||||
void RenderObject::move( int ticks ) {
|
||||
if ( permanent )
|
||||
return;
|
||||
auto addx =
|
||||
static_cast< double >( movementSpeed * movementDirection.getX() ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
auto addy =
|
||||
static_cast< double >( movementSpeed * movementDirection.getY() ) *
|
||||
( static_cast< double >( ticks ) / 1000 );
|
||||
auto addx = movementSpeed * movementDirection.getX() * ticks / 1000.0;
|
||||
auto addy = movementSpeed * movementDirection.getY() * ticks / 1000.0;
|
||||
if ( std::isnan( addx ) || std::isnan( addy ) )
|
||||
return;
|
||||
|
||||
@@ -231,8 +233,8 @@ void RenderObject::resumeAnimation() {
|
||||
void RenderObject::removeAnimation() {
|
||||
animation.clear();
|
||||
}
|
||||
void RenderObject::setAnimationSpeed( const int fps ) {
|
||||
void RenderObject::setAnimationSpeed( const double fps ) {
|
||||
animation_fps = fps;
|
||||
animation_next_frame = 1000 / fps;
|
||||
animation_next_frame = animation_next_frame_base = 1000 / fps;
|
||||
}
|
||||
} // namespace SDLPP
|
||||
|
||||
Reference in New Issue
Block a user