当前位置:编程学习 > wap >>

cocos2d-x CCSprite

 

 


01 //CCSprite
02 
03     //释放到目前为止所有加载的图片
04     CCTextureCache::sharedTextureCache()->removeAllTextures();
05     //加载图片
06     CCSprite *sprite = CCSprite::spriteWithFile("yy.png", CCRectMake(112*0, 64*0, 112, 64));
07     //停止所有动画
08     sprite->stopAllActions();
09     //启动动画
10     sprite->runAction(animate);
11     //播放一次
12     sprite->runAction(CCRepeat::actionWithAction(_animate_go, 1));
13     //重复播放
14     sprite->runAction(CCRepeatForever::actionWithAction(_animate_go));
15 
16     CCAnimate *animate;
17     aimate->stop();  //停止动画
18 
19 
20     //延时调用
21     CCFiniteTimeAction *action1 = CCMoveBy::actionWithDuration(1.0f, ccp(200, 200));
22     CCFiniteTimeAction *action2 = action1->reverse();
23     sprite->runAction(CCSequence::actions(action1, CCDelayTime::actionWithDuration(1.0f), action2, NULL));
24 
25    www.zzzyk.com
26 //函数调用 CCCallFunc
27 void YY::Hello()
28 {
29     CCLog("Hello, this your world!\n");
30 }
31 
32 void YY:Action()
33 {
34     sprite->stopAllActions();
35     CCSpriteFrameCache *sfcache = CCSpriteFrameCache::sharedSpriteFrameCache();
36     sfcache->addSpriteFramesWithFile("yy/yy.plist");
37     CCMutableArray<CCSpriteFrame*> *anim_frames = new CCMutableArray<CCSpriteFrame*>();
38     char tmp[50];
39     for (int j = 0; j < 6; j++)
40     {
41         sprintf(tmp, "yy_%d.png", j);
42         CCSpriteFrame *frame = sfcache->spriteFrameByName(tmp);
43         anim_frames->addObject(frame);
44     }
45 
46     CCAnimation *animation = CCAnimation::animationWithFrames(anim_frames, 0.1f);
47     anim_frames->release();
48 
49     CCAnimate *animate = CCAnimate::actionWithAnimation(animation, false);
50     CCFiniteTimeAction *action = CCCallFunc::actionWithTarget((CCObject*)this, callfunc_selector(YY::Hello));
51     sprite->runAction(CCSequence::actions(animate, action, NULL));
52 }

 

作者:雲瑜
补充:移动开发 , 其他 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,