cocos2dx创造精灵的五种方法

cocos2dx创造精灵的五种方法,第1张

概述//方法一:直接创建精灵           //适合于要显示的是这张图片的全部区域,       CCSprite * sprite = CCSprite::create("Icon.png");           //上面那句话也可以根据需要这样来写:       //CCString* fileName = CCString::createWithFormat("Icon_%d.jpg", //方法一:直接创建精灵 //适合于要显示的是这张图片的全部区域, 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);</span></strong>
//方法二:参数图片名称矩形区域 //适合于需要显示此图片的部分区域 CCSprite*sprite=CCSprite::create("Icon.png",CCRectMake(0,30,30)); sprite->setposition(ccp(100,100)); this->addChild(sprite);</span></strong>
@H_403_105@//方法三:利用帧缓存中的一帧的名称声称一个对象 //适合于pList打包好的文件 CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithfile("test_icon.pList"); CCSprite*sprite=CCSprite::createWithSpriteFramename("Icon.png"); this->addChild(sprite);</span></strong>

//方法四:利用另外一帧生成一个精灵对象 //适合于做帧动画使用 CCSpriteFrame*frame=CCSpriteFrame::create("Icon.png",40,30)); CCSprite*sprite=CCSprite::createWithSpriteFrame(frame); sprite->setposition(ccp(310,150)); addChild(sprite);</span></strong>

//方法五:利用纹理, //适合于需要频繁使用的图片 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);</span></strong> 总结

以上是内存溢出为你收集整理的cocos2dx创造精灵的五种方法全部内容,希望文章能够帮你解决cocos2dx创造精灵的五种方法所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1062314.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存