• cocos2d 帧序列动画


    CCSize size=CCDirector::sharedDirector()->getWinSize(); 
        //第一步:生成动画需要的数据
        CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("number.png");
        //CCRectMake(x,y,width,height)
        //x,y是起点,左上角为(0,0)
        CCSpriteFrame *frmae0=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*0,12,16));
        CCSpriteFrame *frmae1=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*1,12,16));
        CCSpriteFrame *frmae2=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*2,12,16));
        CCSpriteFrame *frmae3=CCSpriteFrame::createWithTexture(texture,CCRectMake(0,19.6*3,12,16));
    
        CCArray *animFrames = CCArray::create();
        animFrames->addObject(frmae0);
        animFrames->addObject(frmae1);
        animFrames->addObject(frmae2);
        animFrames->addObject(frmae3);
    
        //创建帧序列
        CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,2.0f);
        animFrames->release();
        //第二步:初始化并设置Sprite 
        
        CCSprite *sprite =CCSprite::createWithSpriteFrame(frmae0);
        sprite->setPosition(ccp(size.width/2,size.height/2));
        addChild(sprite);
        
        //第三步:使用animation生成一个动画动作animate
        CCAnimate *animate = CCAnimate::create(animation);
        sprite->runAction(CCRepeatForever::create(animate));//重复播放
  • 相关阅读:
    扑克牌顺子
    多任务Multitask Learning
    智能指针
    左旋转字符串
    和为s的两个数字
    07.极简主义读后感
    06.极简主义——汇流(笔记)
    05.极简主义——奉献(笔记)
    04.极简主义——热情(笔记)
    03.极简主义——人际关系(笔记)
  • 原文地址:https://www.cnblogs.com/yufenghou/p/3623766.html
Copyright © 2020-2023  润新知