cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SpriteFrame Class Reference

A SpriteFrame has: More...

#include <CCSpriteFrame.h>

Inheritance diagram for SpriteFrame:
Ref Clonable

Public Member Functions

const RectgetRectInPixels () const
 
void setRectInPixels (const Rect &rectInPixels)
 
bool isRotated () const
 
void setRotated (bool rotated)
 
const RectgetRect () const
 get rect of the frame More...
 
void setRect (const Rect &rect)
 set rect of the frame More...
 
const Vec2getOffsetInPixels () const
 get offset of the frame More...
 
void setOffsetInPixels (const Vec2 &offsetInPixels)
 set offset of the frame More...
 
const SizegetOriginalSizeInPixels () const
 get original size of the trimmed image More...
 
void setOriginalSizeInPixels (const Size &sizeInPixels)
 set original size of the trimmed image More...
 
const SizegetOriginalSize () const
 get original size of the trimmed image More...
 
void setOriginalSize (const Size &sizeInPixels)
 set original size of the trimmed image More...
 
Texture2DgetTexture ()
 get texture of the frame More...
 
void setTexture (Texture2D *pobTexture)
 set texture of the frame, the texture is retained More...
 
const Vec2getOffset () const
 
void setOffset (const Vec2 &offsets)
 
virtual SpriteFrameclone () const override
 returns a copy of the Ref More...
 
virtual ~SpriteFrame ()
 NA More...
 
bool initWithTexture (Texture2D *pobTexture, const Rect &rect)
 Initializes a SpriteFrame with a texture, rect in points. More...
 
bool initWithTextureFilename (const std::string &filename, const Rect &rect)
 Initializes a SpriteFrame with a texture filename, rect in points; It is assumed that the frame was not trimmed. More...
 
bool initWithTexture (Texture2D *pobTexture, const Rect &rect, bool rotated, const Vec2 &offset, const Size &originalSize)
 Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. More...
 
bool initWithTextureFilename (const std::string &filename, const Rect &rect, bool rotated, const Vec2 &offset, const Size &originalSize)
 Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. More...
 
- Public Member Functions inherited from Ref
void retain ()
 Retains the ownership. More...
 
void release ()
 Releases the ownership immediately. More...
 
Refautorelease ()
 Releases the ownership sometime soon automatically. More...
 
unsigned int getReferenceCount () const
 Returns the Ref's current reference count. More...
 
virtual ~Ref ()
 NA NA More...
 
- Public Member Functions inherited from Clonable
virtual ~Clonable ()
 NA NA More...
 
Refcopy () const
 returns a copy of the Ref. More...
 

Static Public Member Functions

static SpriteFramecreate (const std::string &filename, const Rect &rect)
 Create a SpriteFrame with a texture filename, rect in points. More...
 
static SpriteFramecreate (const std::string &filename, const Rect &rect, bool rotated, const Vec2 &offset, const Size &originalSize)
 Create a SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels. More...
 
static SpriteFramecreateWithTexture (Texture2D *pobTexture, const Rect &rect)
 Create a SpriteFrame with a texture, rect in points. More...
 
static SpriteFramecreateWithTexture (Texture2D *pobTexture, const Rect &rect, bool rotated, const Vec2 &offset, const Size &originalSize)
 Create a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels. More...
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: SpriteFrame()
 

Protected Attributes

Vec2 _offset
 
Size _originalSize
 
Rect _rectInPixels
 
bool _rotated
 
Rect _rect
 
Vec2 _offsetInPixels
 
Size _originalSizeInPixels
 
Texture2D_texture
 
std::string _textureFilename
 
- Protected Attributes inherited from Ref
unsigned int _referenceCount
 count of references More...
 

Additional Inherited Members

- Protected Member Functions inherited from Ref
 Ref ()
 Constructor. More...
 

Detailed Description

A SpriteFrame has:

  • texture: A Texture2D that will be used by the Sprite
  • rectangle: A rectangle of the texture

You can modify the frame of a Sprite by doing:

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

Constructor & Destructor Documentation

virtual ~SpriteFrame ( )
virtual

NA

Member Function Documentation

virtual SpriteFrame* clone ( ) const
overridevirtual

returns a copy of the Ref

Implements Clonable.

static SpriteFrame* create ( const std::string &  filename,
const Rect rect 
)
static

Create a SpriteFrame with a texture filename, rect in points.

It is assumed that the frame was not trimmed.

static SpriteFrame* create ( const std::string &  filename,
const Rect rect,
bool  rotated,
const Vec2 offset,
const Size originalSize 
)
static

Create a SpriteFrame with a texture filename, rect, rotated, offset and originalSize in pixels.

The originalSize is the size in pixels of the frame before being trimmed.

static SpriteFrame* createWithTexture ( Texture2D pobTexture,
const Rect rect 
)
static

Create a SpriteFrame with a texture, rect in points.

It is assumed that the frame was not trimmed.

static SpriteFrame* createWithTexture ( Texture2D pobTexture,
const Rect rect,
bool  rotated,
const Vec2 offset,
const Size originalSize 
)
static

Create a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.

The originalSize is the size in points of the frame before being trimmed.

const Vec2& getOffset ( ) const
const Vec2& getOffsetInPixels ( ) const

get offset of the frame

const Size& getOriginalSize ( ) const
inline

get original size of the trimmed image

const Size& getOriginalSizeInPixels ( ) const
inline

get original size of the trimmed image

const Rect& getRect ( ) const
inline

get rect of the frame

const Rect& getRectInPixels ( ) const
inline
Texture2D* getTexture ( )

get texture of the frame

bool initWithTexture ( Texture2D pobTexture,
const Rect rect 
)

Initializes a SpriteFrame with a texture, rect in points.

It is assumed that the frame was not trimmed.

bool initWithTexture ( Texture2D pobTexture,
const Rect rect,
bool  rotated,
const Vec2 offset,
const Size originalSize 
)

Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.

The originalSize is the size in points of the frame before being trimmed.

bool initWithTextureFilename ( const std::string &  filename,
const Rect rect 
)

Initializes a SpriteFrame with a texture filename, rect in points; It is assumed that the frame was not trimmed.

bool initWithTextureFilename ( const std::string &  filename,
const Rect rect,
bool  rotated,
const Vec2 offset,
const Size originalSize 
)

Initializes a SpriteFrame with a texture, rect, rotated, offset and originalSize in pixels.

The originalSize is the size in pixels of the frame before being trimmed.

Since
v1.1
bool isRotated ( ) const
inline
void setOffset ( const Vec2 offsets)
void setOffsetInPixels ( const Vec2 offsetInPixels)

set offset of the frame

void setOriginalSize ( const Size sizeInPixels)
inline

set original size of the trimmed image

void setOriginalSizeInPixels ( const Size sizeInPixels)
inline

set original size of the trimmed image

void setRect ( const Rect rect)

set rect of the frame

void setRectInPixels ( const Rect rectInPixels)
void setRotated ( bool  rotated)
inline
void setTexture ( Texture2D pobTexture)

set texture of the frame, the texture is retained

Member Data Documentation

Vec2 _offset
protected
Vec2 _offsetInPixels
protected
Size _originalSize
protected
Size _originalSizeInPixels
protected
Rect _rect
protected
Rect _rectInPixels
protected
bool _rotated
protected
Texture2D* _texture
protected
std::string _textureFilename
protected

The documentation for this class was generated from the following file: