首页 > 代码库 > cocos2d 动作切换
cocos2d 动作切换
#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 动作切换
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。