学习:cocos2d-x手机游戏开发(三)Create

131页代码:

 1 CCTMXTiledMap *map=CCTMXTiledMap::create("0.tmx");
 2         this->addChild(map);
 3         CCTexture2D *heroTexture=CCTextureCache::sharedTextureCache()->addImage("hero.png");
 4         CCSpriteFrame *frame0,*frame1,*frame2,*frame3;
 5         CCSpriteFrame *frame=new CCSpriteFrame[4];
 6         CCArray *animFrames=new CCArray(4);
 7         frame0=CCSpriteFrame::createWithTexture(heroTexture,CCRectMake(0,0,32,32));
 8         
 9         frame1=CCSpriteFrame::createWithTexture(heroTexture,CCRectMake(32*1,0,32,32));
10         frame2=CCSpriteFrame::createWithTexture(heroTexture,CCRectMake(32*2,0,32,32));
11         frame3=CCSpriteFrame::createWithTexture(heroTexture,CCRectMake(32*3,0,32,32));
12 
13         animFrames->addObject(frame0);
14         animFrames->addObject(frame1);
15         animFrames->addObject(frame2);
16         animFrames->addObject(frame3);
17         CCAnimation *animation=CCAnimation::createWithSpriteFrames(animFrames,0.2f);
18         
19         animFrames->release();
20 
21         CCSprite *heroSprite=CCSprite::createWithSpriteFrame(frame0);
22         heroSprite->setPosition(CCPoint(100,100));
23         this->addChild(heroSprite);
24 
25         
26         CCAnimate *animate=CCAnimate::create(animation);
27         
28         heroSprite->runAction(CCRepeatForever::create(animate));

会发现,2.1.1多数类的方法被带有Create标识的成员所替代。

参考:http://www.cnblogs.com/TerryBlog/archive/2012/11/07/2759506.html

posted @ 2013-02-06 11:59  gwjtssy  阅读(325)  评论(0编辑  收藏  举报