Class Index | File Index

Classes


Class cc.Sprite


Extends cc.Node.

Defined in: CCSprite.js.

Class Summary
Constructor Attributes Constructor Name and Description
 

cc.Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
cc.Sprite can be created with an image, or with a sub-rectangle of an image.

Method Summary
Method Attributes Method Name and Description
 
addChild(child, zOrder, tag)
Add child to sprite (override cc.Node )
<static>  
cc.Sprite.create(fileName, rect)
Create a sprite with filename and rect
<static>  
cc.Sprite.createWithSpriteFrame(spriteFrame)
Creates a sprite with a sprite frame.
<static>  
cc.Sprite.createWithSpriteFrameName(spriteFrame)
Creates a sprite with a sprite frame name
<static>  
cc.Sprite.createWithTexture(texture, rect, offset)
Create a sprite with texture
 
ctor(fileName)
Constructor
 
Returns the current displayed frame.
 
draw(ctx)
draw sprite to canvas
 
Set the index used on the TextureAtlas.
 
 
conforms to cc.TextureProtocol protocol
 
Return color of sprite
 
Get offset position of the sprite.
 
Return opacity of sprite
 
get the quad (tex coords, vertex coords and color) information
 
return the SpriteBatchNode of the cc.Sprite
 
 
getTextureAtlas(pobTextureAtlas)
return the TextureAtlas of the cc.Sprite
 
returns the rect of the cc.Sprite in points
 
IsRelativeAnchorPoint setter (override cc.Node )
 
init()
Initializes a sprite
 
initWithFile(filename, rect)
Initializes a sprite with a texture's filename and a rect in texture
 
initWithSpriteFrame(spriteFrame)
Initializes a sprite with a sprite frame.
 
initWithSpriteFrameName(spriteFrameName)
Initializes a sprite with a sprite frame name.
 
initWithTexture(texture, rect, rotated)
Initializes a sprite with a texture and a rect in texture
 
whether or not the Sprite needs to be updated in the Atlas
 

whether or not the sprite is flipped horizontally.

 

whether or not the sprite is flipped vertically.

 
Returns whether or not a cc.SpriteFrame is being displayed
 
return IsOpacityModifyRGB value
 
returns whether or not the texture rectangle is rotated
 
Removes all children from the container (override cc.Node )
 
removeChild(child, cleanup)
Removes a child from the sprite.
 
reorderChild(child, zOrder)
Reorders a child according to a new z value.
 
HACK: optimization
 
AnchorPoint setter (override cc.Node )
 
setAtlasIndex(atlasIndex)
Set the index used on the TextureAtlas.
 
setBatchNode(spriteBatchNode)
 
setBlendFunc(src, dst)
conforms to cc.TextureProtocol protocol
 
setColor(color3)
color setter
 
setDirty(bDirty)
make the Sprite to be updated in the Atlas.
 
set Recursively is or isn't Dirty used only when parent is CCSpriteBatchNode
 
setDisplayFrame(newFrame)
Sets a new display frame to the cc.Sprite.
 
setDisplayFrameWithAnimationName(animationName, frameIndex)
changes the display frame with animation name and index.
 
setFlipX(flipX)
FlipX value setter (override cc.Node )
 
setFlipY(flipY)
FlipY value setter (override cc.Node )
 
setOpacity(opacity)
opacity setter
 
opacity: conforms to CCRGBAProtocol protocol
 
position setter (override cc.Node )
 
setRotation(rotation)
Rotation setter (override cc.Node )
 
setScale(scale, scaleY)

The scale factor of the node.

 
setScaleX(scaleX)
ScaleX setter (override cc.Node )
 
setScaleY(scaleY)
ScaleY setter (override cc.Node )
 
SkewX setter (override cc.Node )
 
SkewY setter (override cc.Node )
 
setSpriteBatchNode(spriteBatchNode)
set the SpriteBatchNode of the cc.Sprite
 
setTexture(texture)
Texture of sprite setter
 
setTextureAtlas(textureAtlas)
set the TextureAtlas of the cc.Sprite
 
setTextureRect(rect, rotated, untrimmedSize)
updates the texture rect of the CCSprite in points.
 

set the vertex rect.

 
setVertexZ(vertexZ)
VertexZ setter (override cc.Node )
 
setVisible(visible)
visible setter (override cc.Node )
 
 
Update sprite's color
 
updates the quad according the the rotation, position, scale values.
 
useBatchNode(batchNode)
tell the sprite to use batch node render.
Methods borrowed from class cc.Node:
cleanup, convertToNodeSpace, convertToNodeSpaceAR, convertTouchToNodeSpace, convertTouchToNodeSpaceAR, convertToWorldSpace, convertToWorldSpaceAR, description, getActionByTag, getActionManager, getAnchorPoint, getAnchorPointInPoints, getBoundingBox, getBoundingBoxToWorld, getCamera, getChildByTag, getChildren, getChildrenCount, getContentSize, getGLServerState, getGrid, getOrderOfArrival, getParent, getPosition, getPositionX, getPositionY, getRotation, getScale, getScaleX, getScaleY, getScheduler, getShaderProgram, getSkewX, getSkewY, getTag, getUserData, getUserObject, getVertexZ, getZOrder, isIgnoreAnchorPointForPosition, isRunning, isVisible, nodeToParentTransform, nodeToWorldTransform, numberOfRunningActions, onEnter, onEnterTransitionDidFinish, onExit, onExitTransitionDidStart, parentToNodeTransform, pauseSchedulerAndActions, release, removeAllChildrenWithCleanup, removeChildByTag, removeFromParent, removeFromParentAndCleanup, resumeSchedulerAndActions, retain, runAction, schedule, scheduleOnce, scheduleUpdate, scheduleUpdateWithPriority, setActionManager, setContentSize, setGLServerState, setGrid, setNodeDirty, setOrderOfArrival, setParent, setPositionX, setPositionY, setScheduler, setShaderProgram, setTag, setUserData, setUserObject, setZOrder, stopAction, stopActionByTag, stopAllActions, transform, transformAncestors, unschedule, unscheduleAllCallbacks, unscheduleUpdate, update, visit, worldToNodeTransform
Class Detail
cc.Sprite()

cc.Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) )
cc.Sprite can be created with an image, or with a sub-rectangle of an image.
If the parent or any of its ancestors is a cc.SpriteBatchNode then the following features/limitations are valid
- Features when the parent is a cc.BatchNode:
- MUCH faster rendering, specially if the cc.SpriteBatchNode has many children. All the children will be drawn in a single batch.
- Limitations
- Camera is not supported yet (eg: CCOrbitCamera action doesn't work)
- GridBase actions are not supported (eg: CCLens, CCRipple, CCTwirl)
- The Alias/Antialias property belongs to CCSpriteBatchNode, so you can't individually set the aliased property.
- The Blending function property belongs to CCSpriteBatchNode, so you can't individually set the blending function property.
- Parallax scroller is not supported, but can be simulated with a "proxy" sprite.
If the parent is an standard cc.Node, then cc.Sprite behaves like any other cc.Node:
- It supports blending functions
- It supports aliasing / antialiasing
- But the rendering will be slower: 1 draw per children.
The default anchorPoint in cc.Sprite is (0.5, 0.5).

var aSprite = new cc.Sprite();
aSprite.initWithFile("HelloHTML5World.png",cc.rect(0,0,480,320));
Method Detail
addChild(child, zOrder, tag)
Add child to sprite (override cc.Node )
Parameters:
{cc.Sprite} child
{Number} zOrder
child's zOrder
{String} tag
child's tag

<static> {cc.Sprite} cc.Sprite.create(fileName, rect)
Create a sprite with filename and rect
//create a sprite with filename
var sprite1 = cc.Sprite.create("HelloHTML5World.png");

//create a sprite with filename and rect
var sprite2 = cc.Sprite.create("HelloHTML5World.png",cc.rect(0,0,480,320));
Parameters:
{String} fileName
{cc.Rect} rect
Returns:
{cc.Sprite}

<static> {cc.Sprite} cc.Sprite.createWithSpriteFrame(spriteFrame)
Creates a sprite with a sprite frame.
//get a sprite frame
var spriteFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame("grossini_dance_01.png");

//create a sprite with a sprite frame
var sprite = cc.Sprite.createWithSpriteFrameName(spriteFrame);
Parameters:
{cc.SpriteFrame} spriteFrame
Returns:
{cc.Sprite}

<static> {cc.Sprite} cc.Sprite.createWithSpriteFrameName(spriteFrame)
Creates a sprite with a sprite frame name
//create a sprite with a sprite frame
var sprite = cc.Sprite.createWithSpriteFrameName('grossini_dance_01.png');
Parameters:
{String} spriteFrame
name
Returns:
{cc.Sprite}

<static> {cc.Sprite} cc.Sprite.createWithTexture(texture, rect, offset)
Create a sprite with texture
//get an image
var img = cc.TextureCache.getInstance().addImage("HelloHTML5World.png");

//create a sprite with texture
var sprite1 = cc.Sprite.createWithTexture(img);

//create a sprite with texture and rect
var sprite2 = cc.Sprite.createWithTexture(img, cc.rect(0,0,480,320));

//create a sprite with texture and rect and offset
var sprite3 = cc.Sprite.createWithTexture(img, cc.rect(0,0,480,320),cc.p(0,0));
Parameters:
{HTMLImageElement|HTMLCanvasElement|cc.Texture2D} texture
{cc.Rect} rect
rect of the texture
{cc.Point} offset
offset of the texture
Returns:
{cc.Sprite}

ctor(fileName)
Constructor
Parameters:
{String|cc.SpriteFrame|cc.SpriteBatchNode|HTMLImageElement|cc.Texture2D} fileName
sprite construct parameter

{cc.SpriteFrame} displayFrame()
Returns the current displayed frame.
Returns:
{cc.SpriteFrame}

draw(ctx)
draw sprite to canvas
Parameters:
{CanvasContext} ctx
2d context of canvas

{Number} getAtlasIndex()
Set the index used on the TextureAtlas.
Returns:
{Number}

getBatchNode()

{cc.BlendFunc} getBlendFunc()
conforms to cc.TextureProtocol protocol
Returns:
{cc.BlendFunc}

{cc.Color3B} getColor()
Return color of sprite
Returns:
{cc.Color3B}

{cc.Point} getOffsetPosition()
Get offset position of the sprite. Calculated automatically by editors like Zwoptex.
Returns:
{cc.Point}

{Number} getOpacity()
Return opacity of sprite
Returns:
{Number}

{cc.V3F_C4B_T2F_Quad} getQuad()
get the quad (tex coords, vertex coords and color) information
Returns:
{cc.V3F_C4B_T2F_Quad}

{cc.SpriteBatchNode} getSpriteBatchNode()
return the SpriteBatchNode of the cc.Sprite
Returns:
{cc.SpriteBatchNode}

getTexture()

{cc.TextureAtlas} getTextureAtlas(pobTextureAtlas)
return the TextureAtlas of the cc.Sprite
Parameters:
{Boolean} pobTextureAtlas
Returns:
{cc.TextureAtlas}

{cc.Rect} getTextureRect()
returns the rect of the cc.Sprite in points
Returns:
{cc.Rect}

ignoreAnchorPointForPosition(relative)
IsRelativeAnchorPoint setter (override cc.Node )
Parameters:
{Boolean} relative

{Boolean} init()
Initializes a sprite
Returns:
{Boolean}

{Boolean} initWithFile(filename, rect)
Initializes a sprite with a texture's filename and a rect in texture
var mySprite = new cc.Sprite();
mySprite.initWithFile("HelloHTML5World.png",cc.rect(0,0,480,320));
Parameters:
{String} filename
{cc.Rect} rect
Returns:
{Boolean}

{Boolean} initWithSpriteFrame(spriteFrame)
Initializes a sprite with a sprite frame.
var spriteFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame("grossini_dance_01.png");
var sprite = new cc.Sprite();
sprite.initWithSpriteFrame(spriteFrame);
Parameters:
{cc.SpriteFrame} spriteFrame
Returns:
{Boolean}

{Boolean} initWithSpriteFrameName(spriteFrameName)
Initializes a sprite with a sprite frame name.
A cc.SpriteFrame will be fetched from the cc.SpriteFrameCache by name.
If the cc.SpriteFrame doesn't exist it will raise an exception.
var sprite = new cc.Sprite();
sprite.initWithSpriteFrameName("grossini_dance_01.png");
Parameters:
{String} spriteFrameName
Returns:
{Boolean}

{Boolean} initWithTexture(texture, rect, rotated)
Initializes a sprite with a texture and a rect in texture
var img =cc.TextureCache.getInstance().addImage("HelloHTML5World.png");
var mySprite = new cc.Sprite();
mySprite.initWithTexture(img,cc.rect(0,0,480,320));
Parameters:
{cc.Texture2D|HTMLImageElement|HTMLCanvasElement} texture
{cc.Rect} rect
rotated
Returns:
{Boolean}

{Boolean} isDirty()
whether or not the Sprite needs to be updated in the Atlas
Returns:
{Boolean}

{Boolean} isFlippedX()

whether or not the sprite is flipped horizontally.
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:
{Boolean}

{Boolean} isFlippedY()

whether or not the sprite is flipped vertically.
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:
{Boolean}

{Boolean} isFrameDisplayed(frame)
Returns whether or not a cc.SpriteFrame is being displayed
Parameters:
{cc.SpriteFrame} frame
Returns:
{Boolean}

{Boolean} isOpacityModifyRGB()
return IsOpacityModifyRGB value
Returns:
{Boolean}

{Boolean} isTextureRectRotated()
returns whether or not the texture rectangle is rotated
Returns:
{Boolean}

removeAllChildren(cleanup)
Removes all children from the container (override cc.Node )
Parameters:
cleanup
whether or not cleanup all running actions

removeChild(child, cleanup)
Removes a child from the sprite. (override cc.Node )
Parameters:
child
cleanup
whether or not cleanup all running actions

reorderChild(child, zOrder)
Reorders a child according to a new z value. (override cc.Node )
Parameters:
{cc.Node} child
{Number} zOrder

SET_DIRTY_RECURSIVELY()
HACK: optimization

setAnchorPoint(anchor)
AnchorPoint setter (override cc.Node )
Parameters:
{cc.Point} anchor

setAtlasIndex(atlasIndex)
Set the index used on the TextureAtlas.
Parameters:
{Number} atlasIndex

setBatchNode(spriteBatchNode)
Parameters:
spriteBatchNode

setBlendFunc(src, dst)
conforms to cc.TextureProtocol protocol
Parameters:
{Number} src
{Number} dst

setColor(color3)
color setter
Parameters:
{cc.Color3B} color3

setDirty(bDirty)
make the Sprite to be updated in the Atlas.
Parameters:
{Boolean} bDirty

setDirtyRecursively(value)
set Recursively is or isn't Dirty used only when parent is CCSpriteBatchNode
Parameters:
{Boolean} value

setDisplayFrame(newFrame)
Sets a new display frame to the cc.Sprite.
Parameters:
{cc.SpriteFrame} newFrame

setDisplayFrameWithAnimationName(animationName, frameIndex)
changes the display frame with animation name and index.
The animation name will be get from the CCAnimationCache
Parameters:
animationName
frameIndex

setFlipX(flipX)
FlipX value setter (override cc.Node )
Parameters:
{Boolean} flipX

setFlipY(flipY)
FlipY value setter (override cc.Node )
Parameters:
{Boolean} flipY

setOpacity(opacity)
opacity setter
Parameters:
{Number} opacity

setOpacityModifyRGB(value)
opacity: conforms to CCRGBAProtocol protocol
Parameters:
{Boolean} value

setPosition(pos)
position setter (override cc.Node )
Parameters:
{cc.Point} pos

setRotation(rotation)
Rotation setter (override cc.Node )
Parameters:
{Number} rotation

setScale(scale, scaleY)

The scale factor of the node. 1.0 is the default scale factor.
It modifies the X and Y scale at the same time. (override cc.Node )

Parameters:
{Number} scale
scaleY

setScaleX(scaleX)
ScaleX setter (override cc.Node )
Parameters:
{Number} scaleX

setScaleY(scaleY)
ScaleY setter (override cc.Node )
Parameters:
{Number} scaleY

setSkewX(sx)
SkewX setter (override cc.Node )
Parameters:
{Number} sx
SkewX value

setSkewY(sy)
SkewY setter (override cc.Node )
Parameters:
{Number} sy
SkewY value

setSpriteBatchNode(spriteBatchNode)
set the SpriteBatchNode of the cc.Sprite
Parameters:
{cc.SpriteBatchNode} spriteBatchNode

setTexture(texture)
Texture of sprite setter
Parameters:
{HTMLImageElement|HTMLCanvasElement|cc.Texture2D} texture

setTextureAtlas(textureAtlas)
set the TextureAtlas of the cc.Sprite
Parameters:
{cc.TextureAtlas} textureAtlas

setTextureRect(rect, rotated, untrimmedSize)
updates the texture rect of the CCSprite in points.
Parameters:
{cc.Rect} rect
a rect of texture
{Boolean} rotated
{cc.Size} untrimmedSize

setVertexRect(rect)

set 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.
(override this method to generate "double scale" sprites)

Parameters:
rect

setVertexZ(vertexZ)
VertexZ setter (override cc.Node )
Parameters:
{Number} vertexZ

setVisible(visible)
visible setter (override cc.Node )
Parameters:
{Boolean} visible

sortAllChildren()

updateColor()
Update sprite's color

updateTransform()
updates the quad according the the rotation, position, scale values.

useBatchNode(batchNode)
tell the sprite to use batch node render.
Parameters:
{cc.SpriteBatchNode} batchNode

Documentation generated by JsDoc Toolkit 2.4.0 on Wed Jan 09 2013 07:51:53 GMT-0800 (PST)