cocos2d-x  3.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Sprite Nodes

Classes

class  AnimationFrame
 AnimationFrame A frame of the animation. More...
 
class  Animation
 A Animation object is used to perform animations on the Sprite objects. More...
 
class  AnimationCache
 Singleton that manages the Animations. More...
 
class  Sprite
 Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) ) More...
 
class  SpriteBatchNode
 SpriteBatchNode is like a batch node: if it contains children, it will draw them in 1 single OpenGL call (often known as "batch draw"). More...
 
class  SpriteFrame
 A SpriteFrame has: More...
 
class  SpriteFrameCache
 Singleton that handles the loading of the sprite frames. More...
 

Functions

bool isFlipY ()
 
void setFlipY (bool flippedY)
 
virtual std::string getDescription () const override
 Gets the description string. More...
 
virtual ~Sprite (void)
 
virtual bool init (void)
 
virtual bool initWithTexture (Texture2D *texture)
 Initializes a sprite with a texture. More...
 
virtual bool initWithTexture (Texture2D *texture, const Rect &rect)
 Initializes a sprite with a texture and a rect. More...
 
virtual bool initWithTexture (Texture2D *texture, const Rect &rect, bool rotated)
 Initializes a sprite with a texture and a rect in points, optionally rotated. More...
 
virtual bool initWithSpriteFrame (SpriteFrame *pSpriteFrame)
 Initializes a sprite with an SpriteFrame. More...
 
virtual bool initWithSpriteFrameName (const std::string &spriteFrameName)
 Initializes a sprite with an sprite frame name. More...
 
virtual bool initWithFile (const std::string &filename)
 Initializes a sprite with an image filename. More...
 
virtual bool initWithFile (const std::string &filename, const Rect &rect)
 Initializes a sprite with an image filename, and a rect. More...
 
void updateColor (void)
 
virtual void setTextureCoords (Rect rect)
 
virtual void updateBlendFunc (void)
 
virtual void setReorderChildDirtyRecursively (void)
 
virtual void setDirtyRecursively (bool bValue)
 

Variables

CC_CONSTRUCTOR_ACCESS __pad0__: Sprite(void)
 
TextureAtlas * _textureAtlas
 
ssize_t _atlasIndex
 SpriteBatchNode texture atlas (weak reference) More...
 
SpriteBatchNode * _batchNode
 Absolute (real) Index on the SpriteSheet. More...
 
bool _dirty
 Used batch node (weak reference) More...
 
bool _recursiveDirty
 Whether the sprite needs to be updated. More...
 
bool _shouldBeHidden
 Whether all of the sprite's children needs to be updated. More...
 
Mat4 _transformToBatch
 should not be drawn because one of the ancestors is not visible More...
 
BlendFunc _blendFunc
 
Texture2D * _texture
 It's required for TextureProtocol inheritance. More...
 
QuadCommand _quadCommand
 Texture2D object that is used to render the sprite. More...
 
Rect _rect
 quad command More...
 
bool _rectRotated
 Retangle of Texture2D. More...
 
Vec2 _offsetPosition
 Whether the texture is rotated. More...
 
Vec2 _unflippedOffsetPositionFromCenter
 
V3F_C4B_T2F_Quad _quad
 
bool _opacityModifyRGB
 
bool _flippedX
 
bool _flippedY
 Whether the sprite is flipped horizontally or not. More...
 
bool _insideBounds
 Whether the sprite is flipped vertically or not. More...
 

Creators

Sprite invalid index on the SpriteBatchNode

static Sprite * create ()
 Creates an empty sprite without texture. More...
 
static Sprite * create (const std::string &filename)
 Creates a sprite with an image filename. More...
 
static Sprite * create (const std::string &filename, const Rect &rect)
 Creates a sprite with an image filename and a rect. More...
 
static Sprite * createWithTexture (Texture2D *texture)
 Creates a sprite with a Texture2D object. More...
 
static Sprite * createWithTexture (Texture2D *texture, const Rect &rect, bool rotated=false)
 Creates a sprite with a texture and a rect. More...
 
static Sprite * createWithSpriteFrame (SpriteFrame *spriteFrame)
 Creates a sprite with an sprite frame. More...
 
static Sprite * createWithSpriteFrameName (const std::string &spriteFrameName)
 Creates a sprite with an sprite frame name. More...
 

BatchNode methods

virtual void updateTransform (void)
 Updates the quad according the rotation, position, scale values. More...
 
virtual SpriteBatchNode * getBatchNode () const
 Returns the batch node object if this sprite is rendered by SpriteBatchNode. More...
 
virtual void setBatchNode (SpriteBatchNode *spriteBatchNode)
 Sets the batch node to sprite. More...
 

Texture / Frame methods

virtual void setTexture (const std::string &filename)
 Sets a new texture (from a filename) to the sprite. More...
 
virtual void setTexture (Texture2D *texture) override
 Sets a new texture to the sprite. More...
 
virtual Texture2D * getTexture () const override
 returns the Texture2D object used by the sprite More...
 
virtual void setTextureRect (const Rect &rect)
 Updates the texture rect of the Sprite in points. More...
 
virtual void setTextureRect (const Rect &rect, bool rotated, const Size &untrimmedSize)
 Sets the texture rect, rectRotated and untrimmed size of the Sprite in points. More...
 
virtual void setVertexRect (const Rect &rect)
 Sets the vertex rect. More...
 
virtual void setSpriteFrame (const std::string &spriteFrameName)
 Sets a new SpriteFrame to the Sprite. More...
 
virtual void setSpriteFrame (SpriteFrame *newFrame)
 
virtual void setDisplayFrame (SpriteFrame *newFrame)
 
virtual bool isFrameDisplayed (SpriteFrame *pFrame) const
 Returns whether or not a SpriteFrame is being displayed. More...
 
virtual SpriteFrame * getSpriteFrame () const
 Returns the current displayed frame. More...
 
virtual SpriteFrame * getDisplayFrame () const
 
virtual SpriteFrame * displayFrame () const
 

Animation methods

virtual void setDisplayFrameWithAnimationName (const std::string &animationName, ssize_t frameIndex)
 Changes the display frame with animation name and index. More...
 

Sprite Properties' setter/getters

virtual bool isDirty (void) const
 Whether or not the Sprite needs to be updated in the Atlas. More...
 
virtual void setDirty (bool dirty)
 Makes the Sprite to be updated in the Atlas. More...
 
V3F_C4B_T2F_Quad getQuad (void) const
 Returns the quad (tex coords, vertex coords and color) information. More...
 
bool isTextureRectRotated (void) const
 Returns whether or not the texture rectangle is rotated. More...
 
ssize_t getAtlasIndex (void) const
 Returns the index used on the TextureAtlas. More...
 
void setAtlasIndex (ssize_t atlasIndex)
 Sets the index used on the TextureAtlas. More...
 
const Rect & getTextureRect (void)
 Returns the rect of the Sprite in points. More...
 
TextureAtlas * getTextureAtlas (void)
 Gets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode. More...
 
void setTextureAtlas (TextureAtlas *pobTextureAtlas)
 Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode. More...
 
const Vec2getOffsetPosition (void) const
 Gets the offset position of the sprite. More...
 
bool isFlippedX (void) const
 Returns the flag which indicates whether the sprite is flipped horizontally or not. More...
 
void setFlippedX (bool flippedX)
 Sets whether the sprite should be flipped horizontally or not. More...
 
bool isFlipX ()
 
void setFlipX (bool flippedX)
 
bool isFlippedY (void) const
 Return the flag which indicates whether the sprite is flipped vertically or not. More...
 
void setFlippedY (bool flippedY)
 Sets whether the sprite should be flipped vertically or not. More...
 

Functions inherited from TextureProtocol

void setBlendFunc (const BlendFunc &blendFunc) override
 
const BlendFunc & getBlendFunc () const override
 NA NA More...
 

Functions inherited from Node

virtual void setScaleX (float scaleX) override
 Sets the scale (x) of the node. More...
 
virtual void setScaleY (float scaleY) override
 Sets the scale (y) of the node. More...
 
virtual void setScale (float scaleX, float scaleY) override
 Sets the scale (x,y) of the node. More...
 
virtual void setPosition (const Vec2 &pos) override
 NA NA More...
 
virtual void setPosition (float x, float y) override
 Sets the position (x,y) of the node in its parent's coordinate system. More...
 
virtual void setRotation (float rotation) override
 Sets the rotation (angle) of the node in degrees. More...
 
virtual void setRotationSkewX (float rotationX) override
 Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew. More...
 
virtual void setRotationSkewY (float rotationY) override
 Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew. More...
 
virtual void setSkewX (float sx) override
 Changes the X skew angle of the node in degrees. More...
 
virtual void setSkewY (float sy) override
 Changes the Y skew angle of the node in degrees. More...
 
virtual void removeChild (Node *child, bool cleanup) override
 Removes a child from the container. More...
 
virtual void removeAllChildrenWithCleanup (bool cleanup) override
 Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter. More...
 
virtual void reorderChild (Node *child, int zOrder) override
 Reorders a child according to a new z value. More...
 
virtual void addChild (Node *child, int zOrder, int tag) override
 Adds a child to the container with z order and tag. More...
 
virtual void addChild (Node *child, int zOrder, const std::string &name) override
 Adds a child to the container with z order and tag. More...
 
virtual void sortAllChildren () override
 Sorts the children array once before drawing, instead of every time when a child is added or reordered. More...
 
virtual void setScale (float scale) override
 Sets the scale (x,y,z) of the node. More...
 
virtual void setPositionZ (float positionZ) override
 Sets the 'z' coordinate in the position. More...
 
virtual void setAnchorPoint (const Vec2 &anchor) override
 Sets the anchor point in percent. More...
 
virtual void ignoreAnchorPointForPosition (bool value) override
 Sets whether the anchor point will be (0,0) when you position this node. More...
 
virtual void setVisible (bool bVisible) override
 Sets whether the node is visible. More...
 
virtual void draw (Renderer *renderer, const Mat4 &transform, uint32_t flags) override
 Override this method to draw your own node. More...
 
virtual void setOpacityModifyRGB (bool modify) override
 
virtual bool isOpacityModifyRGB (void) const override
 

Detailed Description

Function Documentation

virtual ~Sprite ( void  )
virtual
virtual void addChild ( Node child,
int  localZOrder,
int  tag 
)
overridevirtual

Adds a child to the container with z order and tag.

If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.

Parameters
childA child node
zOrderZ order for drawing priority. Please refer to setLocalZOrder(int)
tagAn integer to identify the node easily. Please refer to setTag(int)

Please use addChild(Node* child, int localZOrder, const std::string &name) instead.

Reimplemented from Node.

virtual void addChild ( Node child,
int  localZOrder,
const std::string &  name 
)
overridevirtual

Adds a child to the container with z order and tag.

If the child is added to a 'running' node, then 'onEnter' and 'onEnterTransitionDidFinish' will be called immediately.

Parameters
childA child node
zOrderZ order for drawing priority. Please refer to setLocalZOrder(int)
nameA string to identify the node easily. Please refer to setName(int)

Reimplemented from Node.

static Sprite* create ( )
static

Creates an empty sprite without texture.

You can call setTexture method subsequently.

Returns
An autoreleased sprite object.
static Sprite* create ( const std::string &  filename)
static

Creates a sprite with an image filename.

After creation, the rect of sprite will be the size of the image, and the offset will be (0,0).

Parameters
filenameA path to image file, e.g., "scene1/monster.png"
Returns
An autoreleased sprite object.
static Sprite* create ( const std::string &  filename,
const Rect rect 
)
static

Creates a sprite with an image filename and a rect.

Parameters
filenameA path to image file, e.g., "scene1/monster.png"
rectA subrect of the image file
Returns
An autoreleased sprite object
static Sprite* createWithSpriteFrame ( SpriteFrame spriteFrame)
static

Creates a sprite with an sprite frame.

Parameters
spriteFrameA sprite frame which involves a texture and a rect
Returns
An autoreleased sprite object
static Sprite* createWithSpriteFrameName ( const std::string &  spriteFrameName)
static

Creates a sprite with an sprite frame name.

A SpriteFrame will be fetched from the SpriteFrameCache by spriteFrameName param. If the SpriteFrame doesn't exist it will raise an exception.

Parameters
spriteFrameNameA null terminated string which indicates the sprite frame name.
Returns
An autoreleased sprite object
static Sprite* createWithTexture ( Texture2D texture)
static

Creates a sprite with a Texture2D object.

After creation, the rect will be the size of the texture, and the offset will be (0,0).

Parameters
textureA pointer to a Texture2D object.
Returns
An autoreleased sprite object
static Sprite* createWithTexture ( Texture2D texture,
const Rect rect,
bool  rotated = false 
)
static

Creates a sprite with a texture and a rect.

After creation, the offset will be (0,0).

Parameters
textureA pointer to an existing Texture2D object. You can use a Texture2D object for many sprites.
rectOnly the contents inside the rect of this texture will be applied for this sprite.
rotatedWhether or not the rect is rotated
Returns
An autoreleased sprite object
virtual SpriteFrame* displayFrame ( ) const
inlinevirtual
virtual void draw ( Renderer renderer,
const Mat4 transform,
uint32_t  flags 
)
overridevirtual

Override this method to draw your own node.

The following GL states will be enabled by default:

  • glEnableClientState(GL_VERTEX_ARRAY);
  • glEnableClientState(GL_COLOR_ARRAY);
  • glEnableClientState(GL_TEXTURE_COORD_ARRAY);
  • glEnable(GL_TEXTURE_2D); AND YOU SHOULD NOT DISABLE THEM AFTER DRAWING YOUR NODE But if you enable any other GL state, you should disable it after drawing your node.

Reimplemented from Node.

Reimplemented in BillBoard.

ssize_t getAtlasIndex ( void  ) const
inline

Returns the index used on the TextureAtlas.

virtual SpriteBatchNode* getBatchNode ( ) const
virtual

Returns the batch node object if this sprite is rendered by SpriteBatchNode.

Returns
The SpriteBatchNode object if this sprite is rendered by SpriteBatchNode, nullptr if the sprite isn't used batch node.
const BlendFunc& getBlendFunc ( void  ) const
inlineoverridevirtual

NA NA

Implements BlendProtocol.

virtual std::string getDescription ( ) const
overridevirtual

Gets the description string.

It makes debugging easier.

Returns
A string NA NA

Reimplemented from Node.

virtual SpriteFrame* getDisplayFrame ( ) const
inlinevirtual
const Vec2& getOffsetPosition ( void  ) const
inline

Gets the offset position of the sprite.

Calculated automatically by editors like Zwoptex.

V3F_C4B_T2F_Quad getQuad ( void  ) const
inline

Returns the quad (tex coords, vertex coords and color) information.

NA NA

virtual SpriteFrame* getSpriteFrame ( ) const
virtual

Returns the current displayed frame.

virtual Texture2D* getTexture ( ) const
overridevirtual

returns the Texture2D object used by the sprite

Implements TextureProtocol.

TextureAtlas* getTextureAtlas ( void  )
inline

Gets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode.

const Rect& getTextureRect ( void  )
inline

Returns the rect of the Sprite in points.

virtual void ignoreAnchorPointForPosition ( bool  ignore)
overridevirtual

Sets whether the anchor point will be (0,0) when you position this node.

This is an internal method, only used by Layer and Scene. Don't call it outside framework. The default value is false, while in Layer and Scene are true

Parameters
ignoretrue if anchor point will be (0,0) when you position this node
Todo:
This method should be renamed as setIgnoreAnchorPointForPosition(bool) or something with "set"

Reimplemented from Node.

virtual bool init ( void  )
virtual

Reimplemented from Node.

virtual bool initWithFile ( const std::string &  filename)
virtual

Initializes a sprite with an image filename.

This method will find filename from local file system, load its content to Texture2D, then use Texture2D to create a sprite. After initialization, the rect used will be the size of the image. The offset will be (0,0).

Parameters
filenameThe path to an image file in local file system
Returns
true if the sprite is initialized properly, false otherwise. init init

Reimplemented in Skin.

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

Initializes a sprite with an image filename, and a rect.

This method will find filename from local file system, load its content to Texture2D, then use Texture2D to create a sprite. After initialization, the offset will be (0,0).

Parameters
filenameThe path to an image file in local file system.
rectThe rectangle assigned the content area from texture.
Returns
true if the sprite is initialized properly, false otherwise. init init
virtual bool initWithSpriteFrame ( SpriteFrame pSpriteFrame)
virtual

Initializes a sprite with an SpriteFrame.

The texture and rect in SpriteFrame will be applied on this sprite

Parameters
pSpriteFrameA SpriteFrame object. It should includes a valid texture and a rect
Returns
true if the sprite is initialized properly, false otherwise.
virtual bool initWithSpriteFrameName ( const std::string &  spriteFrameName)
virtual

Initializes a sprite with an sprite frame name.

A SpriteFrame will be fetched from the SpriteFrameCache by name. If the SpriteFrame doesn't exist it will raise an exception.

Parameters
spriteFrameNameA key string that can fected a volid SpriteFrame from SpriteFrameCache
Returns
true if the sprite is initialized properly, false otherwise.

Reimplemented in Skin.

virtual bool initWithTexture ( Texture2D texture)
virtual

Initializes a sprite with a texture.

After initialization, the rect used will be the size of the texture, and the offset will be (0,0).

Parameters
textureA pointer to an existing Texture2D object. You can use a Texture2D object for many sprites.
Returns
true if the sprite is initialized properly, false otherwise.
virtual bool initWithTexture ( Texture2D texture,
const Rect rect 
)
virtual

Initializes a sprite with a texture and a rect.

After initialization, the offset will be (0,0).

Parameters
textureA pointer to an exisiting Texture2D object. You can use a Texture2D object for many sprites.
rectOnly the contents inside rect of this texture will be applied for this sprite.
Returns
true if the sprite is initialized properly, false otherwise.
virtual bool initWithTexture ( Texture2D texture,
const Rect rect,
bool  rotated 
)
virtual

Initializes a sprite with a texture and a rect in points, optionally rotated.

After initialization, the offset will be (0,0).

Note
This is the designated initializer.
Parameters
textureA Texture2D object whose texture will be applied to this sprite.
rectA rectangle assigned the contents of texture.
rotatedWhether or not the texture rectangle is rotated.
Returns
true if the sprite is initialized properly, false otherwise.
virtual bool isDirty ( void  ) const
inlinevirtual

Whether or not the Sprite needs to be updated in the Atlas.

Returns
true if the sprite needs to be updated in the Atlas, false otherwise.
bool isFlippedX ( void  ) const

Returns the flag which indicates whether the sprite is flipped horizontally or not.

It only flips the texture of the sprite, and not the texture of the sprite's children. Also, flipping the texture doesn't alter the anchorPoint. If you want to flip the anchorPoint too, and/or to flip the children too use: sprite->setScaleX(sprite->getScaleX() * -1);

Returns
true if the sprite is flipped horizontally, false otherwise.
bool isFlippedY ( void  ) const

Return the flag which indicates whether the sprite is flipped vertically or not.

It only flips the texture of the sprite, and not the texture of the sprite's children. Also, flipping the texture doesn't alter the anchorPoint. If you want to flip the anchorPoint too, and/or to flip the children too use: sprite->setScaleY(sprite->getScaleY() * -1);

Returns
true if the sprite is flipped vertically, false otherwise.
bool isFlipX ( )
inline
Deprecated:
Use isFlippedX() instead NA NA
bool isFlipY ( )
inline
virtual bool isFrameDisplayed ( SpriteFrame pFrame) const
virtual

Returns whether or not a SpriteFrame is being displayed.

virtual bool isOpacityModifyRGB ( void  ) const
overridevirtual

Reimplemented from Node.

bool isTextureRectRotated ( void  ) const
inline

Returns whether or not the texture rectangle is rotated.

virtual void removeAllChildrenWithCleanup ( bool  cleanup)
overridevirtual

Removes all children from the container, and do a cleanup to all running actions depending on the cleanup parameter.

Parameters
cleanuptrue if all running actions on all children nodes should be cleanup, false oterwise. removeAllChildren removeAllChildren

Reimplemented from Node.

virtual void removeChild ( Node child,
bool  cleanup 
)
overridevirtual

Removes a child from the container.

It will also cleanup all running actions depending on the cleanup parameter.

Parameters
childThe child node which will be removed.
cleanuptrue if all running actions and callbacks on the child node will be cleanup, false otherwise.

Reimplemented from Node.

virtual void reorderChild ( Node child,
int  localZOrder 
)
overridevirtual

Reorders a child according to a new z value.

Parameters
childAn already added child node. It MUST be already added.
localZOrderZ order for drawing priority. Please refer to setLocalZOrder(int)

Reimplemented from Node.

virtual void setAnchorPoint ( const Vec2 anchorPoint)
overridevirtual

Sets the anchor point in percent.

anchorPoint is the point around which all transformations and positioning manipulations take place. It's like a pin in the node where it is "attached" to its parent. The anchorPoint is normalized, like a percentage. (0,0) means the bottom-left corner and (1,1) means the top-right corner. But you can use values higher than (1,1) and lower than (0,0) too. The default anchorPoint is (0.5,0.5), so it starts in the center of the node.

Note
If node has a physics body, the anchor must be in the middle, you cann't change this to other value.
Parameters
anchorPointThe anchor point of node.

Reimplemented from Node.

void setAtlasIndex ( ssize_t  atlasIndex)
inline

Sets the index used on the TextureAtlas.

Warning
Don't modify this value unless you know what you are doing
virtual void setBatchNode ( SpriteBatchNode spriteBatchNode)
virtual

Sets the batch node to sprite.

Warning
This method is not recommended for game developers. Sample code for using batch node
SpriteBatchNode *batch = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 15);
Sprite *sprite = Sprite::createWithTexture(batch->getTexture(), Rect(0, 0, 57, 57));
batch->addChild(sprite);
layer->addChild(batch);
void setBlendFunc ( const BlendFunc blendFunc)
inlineoverridevirtual
*When this function bound into js or lua,the parameter will be changed
*In js: var setBlendFunc(var src, var dst)
*In lua: local setBlendFunc(local src, local dst)

Implements BlendProtocol.

virtual void setDirty ( bool  dirty)
inlinevirtual

Makes the Sprite to be updated in the Atlas.

virtual void setDirtyRecursively ( bool  bValue)
protectedvirtual
virtual void setDisplayFrame ( SpriteFrame newFrame)
inlinevirtual
virtual void setDisplayFrameWithAnimationName ( const std::string &  animationName,
ssize_t  frameIndex 
)
virtual

Changes the display frame with animation name and index.

The animation name will be get from the AnimationCache

void setFlippedX ( bool  flippedX)

Sets whether the sprite should be flipped horizontally or not.

Parameters
flippedXtrue if the sprite should be flipped horizontally, false otherwise.
void setFlippedY ( bool  flippedY)

Sets whether the sprite should be flipped vertically or not.

Parameters
flippedYtrue if the sprite should be flipped vertically, false otherwise.
void setFlipX ( bool  flippedX)
inline
void setFlipY ( bool  flippedY)
inline
virtual void setOpacityModifyRGB ( bool  modify)
overridevirtual

Reimplemented from Node.

virtual void setPosition ( const Vec2 pos)
overridevirtual

NA NA

Reimplemented from Node.

virtual void setPosition ( float  x,
float  y 
)
overridevirtual

Sets the position (x,y) of the node in its parent's coordinate system.

Passing two numbers (x,y) is much efficient than passing Vec2 object. This method is bound to Lua and JavaScript. Passing a number is 10 times faster than passing a object from Lua to c++

// sample code in Lua
local pos = node::getPosition() -- returns Vec2 object from C++
node:setPosition(x, y) -- pass x, y coordinate to C++
Parameters
xX coordinate for position
yY coordinate for position

Reimplemented from Node.

virtual void setPositionZ ( float  positionZ)
overridevirtual

Sets the 'z' coordinate in the position.

It is the OpenGL Z vertex value.

The OpenGL depth buffer and depth testing are disabled by default. You need to turn them on in order to use this property correctly.

setPositionZ() also sets the setGlobalZValue() with the positionZ as value.

See also
setGlobalZValue()
Parameters
vertexZOpenGL Z vertex of this node.

Reimplemented from Node.

virtual void setReorderChildDirtyRecursively ( void  )
protectedvirtual
virtual void setRotation ( float  rotation)
overridevirtual

Sets the rotation (angle) of the node in degrees.

0 is the default rotation angle. Positive values rotate node clockwise, and negative values for anti-clockwise.

Parameters
rotationThe rotation of the node in degrees.

Reimplemented from Node.

virtual void setRotationSkewX ( float  rotationX)
overridevirtual

Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew.

The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality while the second one uses the real skew function.

0 is the default rotation angle. Positive values rotate node clockwise, and negative values for anti-clockwise.

Parameters
rotationXThe X rotation in degrees which performs a horizontal rotational skew.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setRotationSkewY ( float  rotationY)
overridevirtual

Sets the Y rotation (angle) of the node in degrees which performs a vertical rotational skew.

The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality while the second one uses the real skew function.

0 is the default rotation angle. Positive values rotate node clockwise, and negative values for anti-clockwise.

Parameters
rotationYThe Y rotation in degrees.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setScale ( float  scaleX,
float  scaleY 
)
overridevirtual

Sets the scale (x,y) of the node.

It is a scaling factor that multiplies the width and height of the node and its children.

Parameters
scaleXThe scale factor on X axis.
scaleYThe scale factor on Y axis.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setScale ( float  scale)
overridevirtual

Sets the scale (x,y,z) of the node.

It is a scaling factor that multiplies the width, height and depth of the node and its children.

Parameters
scaleThe scale factor for both X and Y axis.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setScaleX ( float  scaleX)
overridevirtual

Sets the scale (x) of the node.

It is a scaling factor that multiplies the width of the node and its children.

Parameters
scaleXThe scale factor on X axis.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setScaleY ( float  scaleY)
overridevirtual

Sets the scale (y) of the node.

It is a scaling factor that multiplies the height of the node and its children.

Parameters
scaleYThe scale factor on Y axis.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setSkewX ( float  skewX)
overridevirtual

Changes the X skew angle of the node in degrees.

The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality while the second one uses the real skew function.

This angle describes the shear distortion in the X direction. Thus, it is the angle between the Y coordinate and the left edge of the shape The default skewX angle is 0. Positive values distort the node in a CW direction.

Parameters
skewXThe X skew angle of the node in degrees.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setSkewY ( float  skewY)
overridevirtual

Changes the Y skew angle of the node in degrees.

The difference between setRotationalSkew() and setSkew() is that the first one simulate Flash's skew functionality while the second one uses the real skew function.

This angle describes the shear distortion in the Y direction. Thus, it is the angle between the X coordinate and the bottom edge of the shape The default skewY angle is 0. Positive values distort the node in a CCW direction.

Parameters
skewYThe Y skew angle of the node in degrees.
Warning
The physics body doesn't support this.

Reimplemented from Node.

virtual void setSpriteFrame ( const std::string &  spriteFrameName)
virtual

Sets a new SpriteFrame to the Sprite.

virtual void setSpriteFrame ( SpriteFrame newFrame)
virtual
virtual void setTexture ( const std::string &  filename)
virtual

Sets a new texture (from a filename) to the sprite.

It will call setTextureRect() with the texture's content size. TODO: The whole Sprite API needs to be reviewed.

virtual void setTexture ( Texture2D texture)
overridevirtual

Sets a new texture to the sprite.

The Texture's rect is not changed.

Implements TextureProtocol.

void setTextureAtlas ( TextureAtlas pobTextureAtlas)
inline

Sets the weak reference of the TextureAtlas when the sprite is rendered using via SpriteBatchNode.

virtual void setTextureCoords ( Rect  rect)
protectedvirtual
virtual void setTextureRect ( const Rect rect)
virtual

Updates the texture rect of the Sprite in points.

It will call setTextureRect(const Rect& rect, bool rotated, const Size& untrimmedSize) with rotated = false, and utrimmedSize = rect.size.

virtual void setTextureRect ( const Rect rect,
bool  rotated,
const Size untrimmedSize 
)
virtual

Sets the texture rect, rectRotated and untrimmed size of the Sprite in points.

It will update the texture coordinates and the vertex rectangle.

virtual void setVertexRect ( const Rect rect)
virtual

Sets the vertex rect.

It will be called internally by setTextureRect. Useful if you want to create 2x images from SD images in Retina Display. Do not call it manually. Use setTextureRect instead.

virtual void setVisible ( bool  visible)
overridevirtual

Sets whether the node is visible.

The default value is true, a node is default to visible

Parameters
visibletrue if the node is visible, false if the node is hidden.

Reimplemented from Node.

virtual void sortAllChildren ( )
overridevirtual

Sorts the children array once before drawing, instead of every time when a child is added or reordered.

This appraoch can improves the performance massively.

Note
Don't call this manually unless a child added needs to be removed in the same frame

Reimplemented from Node.

virtual void updateBlendFunc ( void  )
protectedvirtual
void updateColor ( void  )
protectedvirtual

Reimplemented from Node.

virtual void updateTransform ( void  )
virtual

Updates the quad according the rotation, position, scale values.

Reimplemented from Node.

Reimplemented in Skin.

Variable Documentation

ssize_t _atlasIndex
protected

SpriteBatchNode texture atlas (weak reference)

SpriteBatchNode* _batchNode
protected

Absolute (real) Index on the SpriteSheet.

BlendFunc _blendFunc
protected
bool _dirty
protected

Used batch node (weak reference)

bool _flippedX
protected
bool _flippedY
protected

Whether the sprite is flipped horizontally or not.

bool _insideBounds
protected

Whether the sprite is flipped vertically or not.

Vec2 _offsetPosition
protected

Whether the texture is rotated.

bool _opacityModifyRGB
protected
V3F_C4B_T2F_Quad _quad
protected
QuadCommand _quadCommand
protected

Texture2D object that is used to render the sprite.

Rect _rect
protected

quad command

bool _rectRotated
protected

Retangle of Texture2D.

bool _recursiveDirty
protected

Whether the sprite needs to be updated.

bool _shouldBeHidden
protected

Whether all of the sprite's children needs to be updated.

Texture2D* _texture
protected

It's required for TextureProtocol inheritance.

TextureAtlas* _textureAtlas
protected
Mat4 _transformToBatch
protected

should not be drawn because one of the ancestors is not visible

Vec2 _unflippedOffsetPositionFromCenter
protected