• cocos2d-x-2.x与3.x帧动画实现方式的改变


    2.x

     //第二个参数表示显示区域的x,y,width,height
        frame0=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*0,0,237.5, 191));
        frame1=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*1,0,237.5, 191));
        frame2=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*2,0,237.5, 191));
        frame3=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*3,0,237.5, 191));
        
    	
        Array *animFrames=Array::create();
        animFrames->addObject(frame0);
        animFrames->addObject(frame1);
        animFrames->addObject(frame2);
        animFrames->addObject(frame3);
        //根据4幅帧生成CCAnimation对象
    	Animation *animation = Animation::createWithSpriteFrames(animFrames);
        
        //根据动画模板创建动画
        animation->setDelayPerUnit(0.2f);
        //animFrames->release();
        Animate *animate=Animate::create(animation);

    3.x

    Vector<SpriteFrame*> frameVec;
    	SpriteFrame* frame = NULL;
    
        //用纹理创建4幅帧动画
        SpriteFrame *frame0,*frame1,*frame2,*frame3;
        //第二个参数表示显示区域的x,y,width,height
        frame0=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*0,0,237.5, 191));
        frame1=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*1,0,237.5, 191));
        frame2=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*2,0,237.5, 191));
        frame3=SpriteFrame::createWithTexture(this->getTexture(),Rect(237.5*3,0,237.5, 191));
        
    	frameVec.pushBack(frame0);
    	frameVec.pushBack(frame1);
    	frameVec.pushBack(frame2);
    	frameVec.pushBack(frame3);
      
        //根据4幅帧生成CCAnimation对象
    	Animation *animation = Animation::createWithSpriteFrames(frameVec);
        
        //根据动画模板创建动画
        animation->setDelayPerUnit(0.2f);
        //animFrames->release();
        Animate *animate=Animate::create(animation);
        return animate;


  • 相关阅读:
    Sql Server 2005中的架构(Schema)、用户(User)、角色(Role)和登录(Login)(三)
    安装Eclipse的Tomcat插件
    Datedif函数
    web.xml 中的listener、 filter、servlet 加载顺序及其详解(1)
    Sql Server 2005中的架构(Schema)、用户(User)、角色(Role)和登录(Login)一
    关于IIS6.0 发布Web服务的问题 Pete
    什么是Winsock
    RTTI
    Cstring转char、string、int等数据类型的方法
    C++静态成员函数小结
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6091803.html
Copyright © 2020-2023  润新知