cocos2d-x 动画详解之三CCSpriteFrame

CCSpriteFrame


精灵帧

CCTexture2D 将被用于CCSprite

默认的构造方法

通过 图片纹理+纹理上的矩形来创建

或通过 图片纹理+纹理上的矩形+是否旋转+偏移坐标+真实size

 

这里简单讲下

是否旋转

     为了节省图片空间 图片将会被旋转90度

偏移坐标+真实size

     为了节省图片空间 原始图片周围透明区域将被trim


Public Member Functions

const CCRect & getRectInPixels (void)
void setRectInPixels (const CCRect &rectInPixels)
bool isRotated (void)
void setRotated (bool bRotated)
const CCRect & getRect (void)
 get rect of the frame 
void setRect (const CCRect &rect)
 set rect of the frame 
const CCPoint & getOffsetInPixels (void)
 get offset of the frame 
void setOffsetInPixels (const CCPoint &offsetInPixels)
 set offset of the frame 
const CCSize & getOriginalSizeInPixels (void)
 get original size of the trimmed image 
void setOriginalSizeInPixels (const CCSize &sizeInPixels)
 set original size of the trimmed image 
CCTexture2D * getTexture (void)
 get texture of the frame 
void setTexture (CCTexture2D *pobTexture) 设置图片纹理
 set texture of the frame, the texture is retained 
 ~CCSpriteFrame (void)
virtual CCObject * copyWithZone (CCZone *pZone)
bool initWithTexture (CCTexture2D *pobTexture, const CCRect &rect)
 Initializes a CCSpriteFrame with a texture, rect in points. 
bool initWithTexture (CCTexture2D *pobTexture, const CCRect &rect, bool rotated, const CCPoint &offset, const CCSize &originalSize)
 Initializes a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. 

Static Public Member Functions

static CCSpriteFrame * frameWithTexture (CCTexture2D *pobTexture, const CCRect &rect)
 Create a CCSpriteFrame with a texture, rect in points. 
static CCSpriteFrame * frameWithTexture (CCTexture2D *pobTexture, const CCRect &rect, bool rotated, const CCPoint &offset, const CCSize &originalSize)
 Create a CCSpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. 

Protected Attributes

CCRect m_obRectInPixels
bool m_bRotated
CCRect m_obRect
CCPoint m_obOffsetInPixels
CCSize m_obOriginalSizeInPixels
CCTexture2D * m_pobTexture

Detailed Description

CCSpriteFrame has:

  • texture: A CCTexture2D that will be used by the CCSprite
  • rectangle: A rectangle of the texture

You can modify the frame of a CCSprite by doing:

CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture, rect, offset); sprite->setDisplayFrame(frame);


转载于:https://www.cnblogs.com/afly/archive/2012/03/06/2382269.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值