zoukankan      html  css  js  c++  java
  • Cocos2d-x 2.1.5 简单动画

    Cocos2d新版本函数更改了一些。

    下面的代码可以产生一个简单动画。



    //第一步:生成动画需要的数据
    		CCTexture2D *texture=CCTextureCache::sharedTextureCache()->addImage("image.png");
    		CCSpriteFrame *frmae0=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*0,48*0,32,48));
    		CCSpriteFrame *frmae1=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*1,48*0,32,48));
    		CCSpriteFrame *frmae2=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*2,48*0,32,48));
    		CCSpriteFrame *frmae3=CCSpriteFrame::createWithTexture(texture,CCRectMake(32*3,48*0,32,48));
    		
    	    CCArray *animFrames = CCArray::create();
    		animFrames->addObject(frmae0);
    		animFrames->addObject(frmae1);
    		animFrames->addObject(frmae2);
    		animFrames->addObject(frmae3);
    		CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames,0.2f);
    		animFrames->release();
    		//第二步:初始化并设置Sprite 
    		CCSprite *sprite =CCSprite::createWithSpriteFrame(frmae0);
    		sprite->setPosition(ccp(s.width/2,s.height/2));
    		addChild(sprite);
    		//第三步:使用animation生成一个动画动作animate
    		CCAnimate *animate = CCAnimate::create(animation);
    		sprite->runAction(CCRepeatForever::create(animate));//重复播放



  • 相关阅读:
    Python数据类型之列表
    Python数据类型之字符串
    《Python基础篇》之初识Python一
    Python运算符及案例
    linux之50条命令详解
    Python环境安装以及简单案例
    Java Date类的使用总结
    Java基础之Object类
    static关键字的内存分析
    Java基础之关键字static
  • 原文地址:https://www.cnblogs.com/james1207/p/3329092.html
Copyright © 2011-2022 走看看