improve walk animation on low end hardware

This commit is contained in:
Eduardo Bart 2012-06-11 16:03:36 -03:00
parent 8cef6463b3
commit 72f569c250
2 changed files with 13 additions and 3 deletions

View File

@ -54,6 +54,7 @@ Creature::Creature() : Thing()
m_emblem = Otc::EmblemNone;
m_nameCache.setFont(g_fonts.getFont("verdana-11px-rounded"));
m_nameCache.setAlign(Fw::AlignTopCenter);
m_footStep = 0;
}
/*
@ -82,6 +83,7 @@ void Creature::draw(const Point& dest, float scaleFactor, bool animate)
}
internalDrawOutfit(dest + animationOffset * scaleFactor, scaleFactor, animate, animate, m_direction);
m_footStepDrawn = true;
}
void Creature::internalDrawOutfit(const Point& dest, float scaleFactor, bool animateWalk, bool animateIdle, Otc::Direction direction)
@ -304,10 +306,15 @@ void Creature::updateWalkAnimation(int totalPixelsWalked)
if(m_outfit.getCategory() != ThingsType::Creature)
return;
if(totalPixelsWalked == 32 || totalPixelsWalked == 0 || getAnimationPhases() <= 1)
int footAnimPhases = getAnimationPhases() - 1;
if(totalPixelsWalked == 32 || footAnimPhases == 0)
m_walkAnimationPhase = 0;
else if(getAnimationPhases() > 1)
m_walkAnimationPhase = 1 + ((totalPixelsWalked * 4) / Otc::TILE_PIXELS) % (getAnimationPhases() - 1);
else if(m_footStepDrawn && m_footTimer.ticksElapsed() >= m_walkAnimationInterval / 4 ) {
m_footStep++;
m_walkAnimationPhase = 1 + (m_footStep % footAnimPhases);
m_footStepDrawn = false;
m_footTimer.restart();
}
}
void Creature::updateWalkOffset(int totalPixelsWalked)

View File

@ -129,11 +129,14 @@ protected:
// walk related
int m_walkAnimationPhase;
int m_footStep;
Timer m_walkTimer;
Timer m_footTimer;
TilePtr m_walkingTile;
int m_walkInterval;
int m_walkAnimationInterval;
Boolean<false> m_walking;
Boolean<false> m_footStepDrawn;
ScheduledEventPtr m_walkUpdateEvent;
Point m_walkOffset;
Otc::Direction m_walkTurnDirection;