码迷,mamicode.com
首页 > 其他好文 > 详细

Sprite(精灵)

时间:2015-03-30 20:37:32      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

用来作为以后复习使用。

1
#include "ScenceScend.h" 2 3 CCScene* ScenceScend::scene() 4 { 5 CCScene* s = CCScene::create(); 6 ScenceScend* layer = ScenceScend::create(); 7 s->addChild(layer); 8 return s; 9 10 } 11 bool ScenceScend::init() 12 { 13 CCLayer::init(); 14 //1.通过文件直接创建精灵 15 //CCSprite* sprite = CCSprite::create(); 16 //CCSprite* sprite = CCSprite::create(filename,CCRect); 17 //CCSprite* sprite = CCSprite::create(filename); 18 19 20 //2.通过纹理去创建精灵 21 22 //CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("filename"); 23 //CCSprite* sprite = CCSprite::createWithTexture(texture); 24 //CCSprite* sprite = CCSprite::createWithTexture(texture,CCRect);也可取图片局部 25 //addChild(sprite); 26 //3通过精灵帧来创建 27 /* 28 CCSize size = CCDirector::sharedDirector()->getWinSize(); 29 30 CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png"); 31 CCSize size2 = texture->getContentSize(); 32 CCSpriteFrame* frame = 33 CCSpriteFrame::createWithTexture(texture, CCRectMake(size2.height / 4, size2.width / 4, size2.width / 2, size2.width / 2)); 34 CCSprite* sprite = CCSprite::createWithSpriteFrame(frame); 35 sprite->setPosition(size.width/2,size.height/2); 36 addChild(sprite); 37 */ 38 39 //4.通过精灵帧缓存 去创建精灵 40 41 CCSize size = CCDirector::getInstance()->getWinSize(); 42 //CCTexture2D 贴图类 43 CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("HelloWorld.png"); 44 CCSize size2 = texture->getContentSize(); 45 CCSpriteFrame* frame = 46 CCSpriteFrame::createWithTexture(texture, CCRectMake(size2.height / 4, size2.width / 4, size2.width / 2, size2.width / 2)); 47 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFrame(frame,"HXL"); 48 CCSprite* sprite = CCSprite::createWithSpriteFrameName("HXL"); 49 sprite->setPosition(size.width / 2, size.height / 2); 50 addChild(sprite); 51 52 /* 53 //调用父类的初始化。因此这里是 子类方法覆盖父类了。 54 CCLayer::init(); 55 CCLabelTTF *label = CCLabelTTF::create("hxltom","Arial",36); 56 label->setPosition(CCPoint(100,200)); 57 addChild(label); 58 */ 59 60 return true; 61 }

 

Sprite(精灵)

标签:

原文地址:http://www.cnblogs.com/tom987690183/p/4378951.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!