方法一:直接创建精灵
适合于要显示的是这张图片的全部区域,
1 | CCSprite * sprite = CCSprite::create( "Icon.png" ); |
CCString* filename = CCString::createWithFormat( "Icon_%d.jpg" ,flag); CCSprite* sprite = CCSprite::create(filename->getCString()); sprite->setposition(ccp(100,100)); this ->addChild(sprite); |
方法二:参数 图片名称 矩形区域
适合于需要显示此图片的部分区域
->addChild(sprite); |
方法三: 利用帧缓存中的一帧的名称声称一个对象
适合于pList打包好的文件
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithfile( "test_icon.pList" ); CCSprite * sprite = CCSprite::createWithSpriteFramename( ); |
方法四: 利用另外一帧生成一个精灵对象
适合于做帧动画使用
方法五:利用纹理
适合于需要频繁使用的图片
CCSpriteBatchNode* spriteTexture = CCSpriteBatchNode::create( "iocn.png" spriteTexture->setposition(CCPointZero); addChild(spriteTexture); CCSprite* sprite = CCSprite::createWithTexture(spriteTexture->getTexture()); sprite->setposition(ccp(visiblesize.wIDth/2,100)); spriteTexture->addChild(sprite,2); |
以上是内存溢出为你收集整理的Cocos2d-x 创建精灵的五种方法全部内容,希望文章能够帮你解决Cocos2d-x 创建精灵的五种方法所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)