/** * Internal function for updating the sprite's animation. * Useful for cases when you need to update this but are buried down in too many supers. * This function is called automatically by <code>FlxSprite.update()</code>. */ void Sprite::updateAnimation() { if(_bakedRotation) { unsigned int oc = _caf; _caf = fmod(angle,360) / _bakedRotation; if(oc != _caf) calcFrame(); return; } if((_curAnim) && (_curAnim->delay > 0) && (_curAnim->looped || !finished)) { _frameTimer += Globals::elapsed; if(_frameTimer > _curAnim->delay) { _frameTimer -= _curAnim->delay; if(_curFrame == _curAnim->frames.size()-1) { if(_curAnim->looped) _curFrame = 0; finished = true; } else { _curFrame++; } _caf = _curAnim->frames[_curFrame]; calcFrame(); } } }
void Sprite::play(const std::string &AnimName, bool Force) { if(!Force && (_curAnim != NULL) && (AnimName == _curAnim->name) && (_curAnim->looped || !finished)) return; _curFrame = 0; _caf = 0; _frameTimer = 0; unsigned int al = _animations.size(); for(unsigned int i = 0; i < al; i++) { if(_animations[i]->name == AnimName) { _curAnim = _animations[i]; if(_curAnim->delay <= 0) finished = true; else finished = false; _caf = _curAnim->frames[_curFrame]; calcFrame(); return; } } }
// Set a new bitmap into the sprite. If the number is the same as the // current one, nothing is done. void CardSprite::setFrame(int no, bool force) { if (!force && no == mCurrentFrame) return; if (no<0 || no >=mFrames.count()) return; // Calulate Pixmap (only done if necessary) calcFrame(no); // Set frame pixmap QPixmap pixmap = mFrames.at(no); setPixmap(pixmap); // Translation QPoint offset = thememanager()->getOffset(); resetTransform(); translate(mHotspots[no].x()+offset.x(), mHotspots[no].y()+offset.y()); mCurrentFrame = no; update(); }