1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include "GameObject.h"
#include "common.h"
void GameObject::shiftBetweenPages( int inPageA, int inPageB,
int inNumSteps ) {
mShiftingPages = true;
mShiftPageA = inPageA;
mShiftPageB = inPageB;
mNumShiftSteps = inNumSteps;
mNumShiftStepsDone = 0;
}
void GameObject::draw( double inRotation, Vector3D *inPosition,
double inScale,
double inFadeFactor,
Color *inColor ) {
if( mSprite == NULL ) {
return;
}
if( !mShiftingPages ) {
mSprite->draw( mSpriteFrame, inRotation, inPosition,
inScale, inFadeFactor, inColor );
}
else {
int oldPage = mSprite->getPage();
double bBlend = mNumShiftStepsDone / (double)mNumShiftSteps;
bBlend = smoothBlend( bBlend );
// draw A at full blend
mSprite->setPage( mShiftPageA );
mSprite->draw( mSpriteFrame, inRotation, inPosition,
inScale, inFadeFactor, inColor );
// fade B in on top
mSprite->setPage( mShiftPageB );
mSprite->draw( mSpriteFrame, inRotation, inPosition,
inScale, inFadeFactor * bBlend, inColor );
// restore page
mSprite->setPage( oldPage );
}
}
void GameObject::mainStep() {
if( mShiftingPages ) {
mNumShiftStepsDone ++;
if( mNumShiftStepsDone > mNumShiftSteps ) {
mShiftingPages = false;
}
}
// call child's step function
step();
}
|