• 动作-CCActionInterval之CCAnimation&CCAnimate


    动画简单实例

    201311182109.jpg

        pic2476.png

    简单的动画代码:

    CCSize winSize=CCDirector::sharedDirector()->getWinSize();         //#1:生成动画需要的数据类     CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage(“pic2476.png”);    CCSpriteFrame *frame0=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*0,48*0,32,48));    CCSpriteFrame *frame1=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*1,48*0,32,48));    CCSpriteFrame *frame2=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*2,48*0,32,48));    CCSpriteFrame *frame3=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*3,48*0,32,48));     CCArray *arrayFrames=CCArray::create();    arrayFrames->addObject(frame0);    arrayFrames->addObject(frame1);    arrayFrames->addObject(frame2);    arrayFrames->addObject(frame3);     CCAnimation *animation=CCAnimation::createWithSpriteFrames(arrayFrames,0.2f);    //#2:初始化并设置Sprite    CCSprite *sprite=CCSprite::createWithSpriteFrame(frame0);    sprite->setPosition(ccp(winSize.width/2,winSize.height/2));    addChild(sprite);    //#3:使用animation生成一个动画动作animate     CCAnimate *animate=CCAnimate::create(animation);    sprite->runAction(CCRepeatForever::create(animate));

    注意,cocos2dx不支持使用clip的动画,另外,clip动画的开发成本很高,在智能手机这种大内存的平台是否适用(牺牲内存换开发速度么?),值得商量。

    #2 相关的类关系图

    说明: http://img1.51cto.com/attachment/201201/122458884.png

    简单过程是,使用CCTexture2D加载图片 ,用CCTexture2D生成对应的CCSpriteFrame(对应的就是帧),将CCSpriteFrame添加到CCAnimation生成动画数据,用CCAnimation生成CCAnimate(就是最终的动画动作),最后用CCSprite执行这个动作。

  • 相关阅读:
    Centos 6.4 8250/16550 只生成了4个串口
    Warning: Data truncated for column 'AirPress' at row 1
    I.MX6 32G SD卡测试
    oracle创建数据库表空间
    oracle创建表空间
    SpringMvc文件下载
    怎么取消ie浏览器body与html的间隙
    Ztree手风琴效果(第三版)
    判断JS对象是否拥有某属性
    js代码判断浏览器种类IE、FF、Opera、Safari、chrome及版本
  • 原文地址:https://www.cnblogs.com/yssgyw/p/3430234.html
Copyright © 2020-2023  润新知