本文整理汇总了C++中CCAnimation::addSpriteFrameWithTexture方法的典型用法代码示例。如果您正苦于以下问题:C++ CCAnimation::addSpriteFrameWithTexture方法的具体用法?C++ CCAnimation::addSpriteFrameWithTexture怎么用?C++ CCAnimation::addSpriteFrameWithTexture使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CCAnimation
的用法示例。
在下文中一共展示了CCAnimation::addSpriteFrameWithTexture方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: resultAni
CCAnimate* PlayScene::resultAni(int value)
{
CCAnimation* animation = CCAnimation::create();
animation->setDelayPerUnit(.2);
for(int i=0;i<value;i++)
{
animation->addSpriteFrameWithTexture(sprite->getTexture(),CCRectMake(120*i,0,120,90));
}
CCAnimate* animate = CCAnimate::create(animation);
return animate;
}
示例2: GetSprite
CCAnimate *createHeroAppearAnim()
{
CCAnimation *animation = CCAnimation::create();
animation->setDelayPerUnit(0.08);
for(int i = 1 ; i <= 11 ; i++){
CCSprite *tex = GetSprite("gameui/qiu1_"+toStr(i) + ".png");
animation->addSpriteFrameWithTexture(tex->getTexture() , tex->getTextureRect());
}
CCAnimate *anim = CCAnimate::create(animation);
return anim;
}
示例3: createDragon
void MyScene::createDragon(CCPoint dragonPosition){
CCTexture2D* texture = CCDirector::getInstance()->getTextureCache()->addImage("Animations/dragon_animation.png");
CCAnimation* animation = Animation::create();
animation->setDelayPerUnit(0.05f);
for (int i = 0; i < 6; ++i){
int index = 1 % 4;
int rowIndex = i / 4;
animation->addSpriteFrameWithTexture(texture, Rect(index * 130, rowIndex * 140, 130, 140));
}
CCSprite* pDragon = Sprite::createWithTexture(texture, Rect(0, 0, 130, 140));
pDragon->setPosition(dragonPosition);
pDragon->setFlippedX(true);
pDragon->setScale(0.5);
pDragon->setName("Dragon");
CCTMXTiledMap* pTmap = (CCTMXTiledMap*)backgroundNode->getChildByName("Tmap");
pTmap->addChild(pDragon, 3, 15);
CCSprite* fireAim = CCSprite::create("line.PNG");
fireAim->setPosition(pDragon->getContentSize().width / 2, pDragon->getContentSize().height / 3);
fireAim->setName("Aim");
fireAim->setScale(0.3f);
fireAim->setAnchorPoint(ccp(-0.5f, 0.5f));
pDragon->addChild(fireAim, 2);
CCSprite* bullet = CCSprite::create("bullet.PNG");
bullet->setName("Bullet");
bullet->setVisible(false);
bullet->setScale(0.3f);
bullet->setPosition(ccp(5.0f, 5.0f));
this->addChild(bullet);
Animate* animate = Animate::create(animation);
RepeatForever* rep = RepeatForever::create(animate);
pDragon->runAction(rep);
pJYPlayerDragon = new JYPlayer(pDragon);
JYArm* pJYArmBullet = new JYArm(bullet);
pJYArmBullet->setName("JYBullet");
pJYPlayerDragon->addChild(pJYArmBullet);
}
示例4: SetWingAction
CCSprite* MainGameScene::SetWingAction()
{
CCSprite* wingSprite = CCSprite::createWithTexture(
_mPlayerBatchNode->getTexture(),
CCRectMake(0, DEFAULT_IMAGE_SIZE, DEFAULT_IMAGE_SIZE, DEFAULT_IMAGE_SIZE)
);
wingSprite->setAnchorPoint(ccp(0, 0));
CCAnimation* wingAnimation = CCAnimation::create();
wingAnimation->setDelayPerUnit(0.05f);
for(int i=0; i<6; ++i)
{
wingAnimation->addSpriteFrameWithTexture(
_mPlayerBatchNode->getTexture(),
CCRectMake(i*DEFAULT_IMAGE_SIZE, DEFAULT_IMAGE_SIZE, DEFAULT_IMAGE_SIZE, DEFAULT_IMAGE_SIZE)
);
}
CCAnimate* wingAnimate = CCAnimate::create(wingAnimation);
wingSprite->runAction( CCRepeatForever::create(wingAnimate));
return wingSprite;
}
示例5: init
bool GameLayer::init(void)
{
bool bRet = false;
do
{
CC_BREAK_IF(!CCLayer::init());
// 游戏场景背景图
CCSprite *bg = CCSprite::spriteWithFile("Space.png");
CC_BREAK_IF(!bg);
bg->setAnchorPoint(CCPointZero);
// 为了突出游戏场景中的精灵,将背景色彩变淡
bg->setOpacity(100);
this->addChild(bg, 0, 1);
// 使用位图字体显示游戏时间
CCLabelBMFont* lbScore = CCLabelBMFont::labelWithString("Time: 0", "font09.fnt");
CC_BREAK_IF(!lbScore);
lbScore->setAnchorPoint(ccp(1, 1));
lbScore->setScale(0.6f);
this->addChild(lbScore, 1, 3);
lbScore->setPosition(ccp(310, 450));
// 载入飞船图像集
CCSpriteBatchNode* mgr = CCSpriteBatchNode::batchNodeWithFile("flight.png", 5);
CC_BREAK_IF(!mgr);
this->addChild(mgr, 0, 4);
// 在状态栏显示一个飞船的图标
CCSprite* sprite = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30));
CC_BREAK_IF(!sprite);
mgr->addChild(sprite, 1, 5);
sprite->setScale(1.1f);
sprite->setAnchorPoint(ccp(0, 1));
sprite->setPosition(ccp(10, 460));
// 显示当前飞船生命条数
CCLabelBMFont* lbLife = CCLabelBMFont::labelWithString("3", "font09.fnt");
CC_BREAK_IF(!lbLife);
lbLife->setAnchorPoint(ccp(0, 1));
lbLife->setScale(0.6f);
this->addChild(lbLife, 1, 6);
lbLife->setPosition(ccp(50, 450));
// 设定时间回调函数,修改游戏用时显示
this->schedule(schedule_selector(GameLayer::step), 1.0f);
// 显示飞船,飞船有不断闪烁的火焰喷射效果
flight = CCSprite::spriteWithTexture(mgr->getTexture(), CCRectMake(0, 0, 31, 30));
CC_BREAK_IF(!flight);
flight->setPosition(ccp(160, 30));
flight->setScale(1.6f);
mgr->addChild(flight, 1, 99);
// 设定动画每一帧的内容
CCAnimation* animation = CCAnimation::animation();
CC_BREAK_IF(!animation);
animation->setName("flight");
animation->setDelayPerUnit(0.2f);
for (int i = 0; i < 3; ++i)
{
int x = i % 3;
animation->addSpriteFrameWithTexture(mgr->getTexture(), CCRectMake(x*32, 0, 31, 30));
}
// 基于动画创建动作
CCAnimate* action = CCAnimate::actionWithAnimation(animation);
CC_BREAK_IF(!action);
// 主角精灵不断重复动作,实现动态飞行效果
flight->runAction(CCRepeatForever::actionWithAction(action));
// accept touch now
this->setTouchEnabled(true);
bRet = true;
} while (false);
return bRet;
}
示例6: runActionWithMotion
void Animal::runActionWithMotion(MOTION motion)
{
CCAnimation *animation = CCAnimation::create();
animation->setDelayPerUnit(0.1f);
for( int iFrame = 0; iFrame < SPRITE_FRAME; iFrame++ )
{
CCTexture2D *pTexture = animates[motion][iFrame];
CCSize sizeTexture = pTexture->getContentSize();
animation->addSpriteFrameWithTexture(pTexture, CCRectMake(0, 0, sizeTexture.width, sizeTexture.height));
}
CCAnimate *animate = CCAnimate::create(animation);
CCFiniteTimeAction *action;
CCPoint direction;
animate->setDuration(duration[motion]);
switch(motion)
{
case WALK_LEFT:
case RUN_LEFT:
direction = ccp(-1.f, -1.f); break;
case WALK_RIGHT:
case RUN_RIGHT:
direction = ccp( 1.f, -1.f); break;
case WALK_BACK_LEFT:
case RUN_BACK_LEFT:
direction = ccp(-1.f, 1.f); break;
case WALK_BACK_RIGHT:
case RUN_BACK_RIGHT:
direction = ccp( 1.f, 1.f); break;
}
switch(motion)
{
case WALK_LEFT:
case WALK_RIGHT:
case WALK_BACK_LEFT:
case WALK_BACK_RIGHT:
{
CCPoint walk = ccp(direction.x*walk_scale.x, direction.y*walk_scale.y);
action = CCSequence::actions(
CCSpawn::actions(CCMoveBy::create(duration[motion], walk), animate, NULL),
CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
}
break;
case RUN_LEFT:
case RUN_RIGHT:
case RUN_BACK_LEFT:
case RUN_BACK_RIGHT:
{
CCPoint run = ccp(direction.x*run_scale.x, direction.y*run_scale.y);
action = CCSequence::actions(
CCSpawn::actions(CCMoveBy::create(duration[motion], run), animate, NULL),
CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
}
break;
case STAND:
case SIT:
case SLEEP:
case EAT:
case POOP:
case SICK:
case FUN_SWING:
case FUN_RUNNING:
case FUN_ROPE:
action = CCSequence::actions(
animate,
CCCallFuncN::actionWithTarget(this, callfuncN_selector(Animal::finishChk)), NULL);
break;
}
motionState.name = motion;
pBody->runAction(action);
}