zoukankan      html  css  js  c++  java
  • 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) 
    {
    
    }
  • 相关阅读:
    求两个数的最大公约数--简单
    输入7个人的成绩,找出大于平均成绩的值--简单
    回文--简单
    约瑟夫环--中等难度
    数组中查找最大数和次大数--简单
    Docker在云环境中的应用实践初探:优势、局限性与效能评测
    基于mongoDB的capped collection的性能优化
    微软开放技术(中国)携 CKAN 和 OData 技术引入基于 Azure 的开放数据平台
    ThreadPoolExecutor原理及使用
    通过 Azure Media Encoder 降低编码成本
  • 原文地址:https://www.cnblogs.com/yufenghou/p/3992028.html
Copyright © 2011-2022 走看看