cocos2d 动作切换
2014-09-25 09:04
155 查看
#include "HelloWorldScene.h" USING_NS_CC; CCScene* HelloWorld::scene() { CCScene *scene = CCScene::create(); HelloWorld *layer = HelloWorld::create(); scene->addChild(layer); return scene; } bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } CCSize winSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("hero.plist"); tank= CCSprite::createWithSpriteFrameName("hero_1.png"); tank->setPosition(ccp(winSize.width/2,winSize.height/2)); addChild(tank); initCreep(); this->scheduleOnce(schedule_selector(HelloWorld::start), 3.0f); this->scheduleOnce(schedule_selector(HelloWorld::stop), 6.0f); this->scheduleOnce(schedule_selector(HelloWorld::restart), 9.0f); this->scheduleUpdate(); return true; } void HelloWorld::initCreep() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("hero.plist"); } void HelloWorld::start(float t) { CCLOG("start"); CCAnimation* animation=CCAnimation::create(); CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache() ->spriteFrameByName("hero_1.png"); animation->addSpriteFrame(frame1); CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache() ->spriteFrameByName("hero_2.png"); animation->addSpriteFrame(frame2); animation->setDelayPerUnit(0.1); animation->setRestoreOriginalFrame(true); creep=CCRepeatForever::create(CCAnimate::create(animation)); tank->runAction(creep); } void HelloWorld::restart(float t) { CCLOG("restart"); CCAnimation* animation=CCAnimation::create(); CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache() ->spriteFrameByName("hero_1.png"); animation->addSpriteFrame(frame1); CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache() ->spriteFrameByName("hero_2.png"); animation->addSpriteFrame(frame2); animation->setDelayPerUnit(0.1); animation->setRestoreOriginalFrame(true); creep=CCRepeatForever::create(CCAnimate::create(animation)); tank->runAction(creep); } void HelloWorld::stop(float t) { CCLOG("stop"); tank->stopAction(creep); } void HelloWorld::update(float t) { }
相关文章推荐
- Cocos2d-x特效:场景切换效果、控件动作、逐帧动画
- [cocos2d-x]动作+场景切换
- [cocos2d-x]动作+场景切换
- cocos2d-x游戏角色待机和奔跑动作切换测试
- cocos2d-Lua06动作和动画切换
- 【Cocos2D学习】Lua——动画动作、场景切换的基本应用
- Cocos2d-x入门之坐标系,场景切换,动作(第五篇)[版本:cocos2d-x-3.1.1]
- cocos2d-x精灵切换动作出错
- [置顶] 游戏开发技术总结(经典之作)第五集 轻松走四方-----游戏角色的移动和动作的切换
- COCOS2D-X 动作 CCSequence动作序列
- cocos2d-x 3.0 场景切换特效汇总
- 六 手游开发神器 cocos2d-x editor 之场景切换
- cocos2d-x-lua:API-瞬时动作
- Cocos2d-x之层间切换
- 【iOS-Cocos2d游戏开发之二十二 】CCSpeed实现CCAnimate动画进行时设置慢动作以及设置游戏加减速进行(塔防游戏必备)! .
- cocos2d-x lua 动作(动画)回调
- 20、Cocos2dx 3.0游戏开发找小三之Cocos2d-x的动作机制:嘻,善哉!技盖至此乎?
- cocos2d之场景切换动画效果
- 使用FlashCS6制作cocos2d-x动作脚本的思路整理
- cocos2d-x提供的场景切换效果