void SpriteAnimator::update(float delta) { Animator::update(delta); if(const auto& animation = getAnimation()) { const auto& currentFrame = animation->getFrameAt(getCurrentFrameIndex()); const auto& currentFrameRectangle = currentFrame.getSourceRectangle(); sourceRectangle.top = currentFrameRectangle.getTop(); sourceRectangle.width = currentFrameRectangle.getWidth(); sourceRectangle.height = currentFrameRectangle.getHeight(); sourceRectangle.left = currentFrameRectangle.getLeft(); sprite.setTextureRect(sourceRectangle); sprite.setOrigin( static_cast<float>(currentFrame.getHotspot().getX()), static_cast<float>(currentFrame.getHotspot().getY()) ); if(invertXOffset) { sprite.setOrigin( static_cast<float>(currentFrame.getSourceRectangle().getWidth() - currentFrame.getHotspot().getX()), static_cast<float>(sprite.getOrigin().y) ); } if(invertYOffset) { sprite.setOrigin( static_cast<float>(sprite.getOrigin().x), static_cast<float>(currentFrame.getSourceRectangle().getHeight() - currentFrame.getHotspot().getY()) ); } } }
void Explosion::restart(cocos2d::Vec2 position) { setPosition(position); //Create an explosion animation among 3 different styles int row = random(0, 2); auto animation = createAnimation("textures/explosion.png", row, 128, 0.05f); //Find the current frame the created animation and set mSprite's spriteFrame int index = animation->getCurrentFrameIndex(); auto currentFrame = animation->getAnimation()->getFrames().at(index)->getSpriteFrame(); _sprite->setSpriteFrame(currentFrame); auto endCallback = CallFunc::create(CC_CALLBACK_0(Explosion::end, this)); _sprite->runAction(Sequence::create(animation, endCallback, NULL)); }
/*! \fn void DataManager::displayUndistortedFrame(Kernel *k1, Kernel *kernel, int winw, int winh, float time, int trcount, int ftcount, int ftadded) \brief Display the undistorted frame \param k1, kernel: Use this fragment program object to display the texture memory \param winw, winh: window dimensions \param time: timing per frame \param ftcount: how many feature to be tracked \param trcount: how many features were tracked \param ftadded: how many features were re-injected */ void DataManager::displayUndistortedFrame(Kernel *k1, Kernel *kernel, int winw, int winh, float time, int maxcount, int trcount, int ftcount, int ftadded) { int w = _image_w; int h = _image_h; char timestring[1024]; sprintf(timestring,"%d x %d video, Time: %8.3lf msec, Features: [MAX %5d] (Tracked %5d of %5d) (Added %5d)", _image_w, _image_h, time, maxcount, trcount, ftcount, ftadded); k1->activate(); DrawText (0.05*winw, 0.9 * winh, timestring, 1.0, 1.0, 1.0); k1->deactivate(); kernel->activate(); kernel->bindInput(getPyramidBlock( getCurrentFrameIndex() , 0, _MAIN_BUF)->_texID); kernel->setRange(w,(int)(1.333*h)); if (_arch == GPU_ATI) kernel->execute(h,0,0,w,0.0,0.0,1.0,1.0); else if (_arch == GPU_NVIDIA) kernel->execute(h,0,0,w,0.0,0.0,h,w); kernel->deactivate(); glDisable(_texTarget); glColor3f(1.0,0.0,0.0); glLineWidth(1.0); glBegin(GL_LINE_LOOP); glVertex2f(-0.998,-0.998); glVertex2f(0.998,-0.998 ); glVertex2f(0.99802, 0.5); glVertex2f(-0.998,0.5); glEnd(); }