加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

cocos2dx Texture、SpriteFrame、Sprite的区别

发布时间:2020-12-14 21:22:19 所属栏目:百科 来源:网络整理
导读:转载自:http://www.jb51.cc/article/p-etvxqupr-bcs.html Texture是保存在GPU缓冲中的一张纹理。是由一张图片创建获得的。 SpriteFrame是Texture+Rect,根据一张纹理材质来剪切获得。 SpriteFrame *spFrame = SpriteFrame::createWithTexture(texture,rect)

转载自:http://www.52php.cn/article/p-etvxqupr-bcs.html

Texture是保存在GPU缓冲中的一张纹理。是由一张图片创建获得的。

SpriteFrame是Texture+Rect,根据一张纹理材质来剪切获得。

SpriteFrame *spFrame = SpriteFrame::createWithTexture(texture,rect);

createWithTexture函数的定义如下:

[cpp] view plain copy print ?
  1. SpriteFrame*SpriteFrame::createWithTexture(Texture2D*texture,constRect&rect)
  2. {
  3. SpriteFrame*spriteFrame=newSpriteFrame();
  4. spriteFrame->initWithTexture(texture,rect);
  5. spriteFrame->autorelease();
  6. returnspriteFrame;
  7. }


使用SpriteFrame 我们可以创建想要见到的Sprite。

Sprite *sp = Sprite::createWithSpriteFrame(spFrame);

这样就通过剪切的Texture创建出了我们想要的Sprite。


Sprite可以动态的改变它的spFrame,这样就形成了精灵帧。

sp->setDisplayFrame(spFrame2);

请看setDisplayFrame的定义:

[cpp] view plain copy print ?
  1. voidsetDisplayFrame(SpriteFrame*newFrame){setSpriteFrame(newFrame);}
  2. voidsetSpriteFrame(SpriteFrame*frame)
  3. {
  4. CC_SAFE_RETAIN(frame);
  5. CC_SAFE_RELEASE(_spriteFrame);
  6. _spriteFrame=frame;
  7. }

这样就动态修改了Sprite的表现了。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读