Class cc.Sprite
Extends
cc.Node.
Defined in: CCSprite.js.
Constructor Attributes | Constructor Name and Description |
---|---|
cc.Sprite is a 2d image ( http://en.wikipedia.org/wiki/Sprite_(computer_graphics) ) |
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
|
|
getColor()
Return color of sprite
|
|
Get offset position of the sprite.
|
|
Return opacity of sprite
|
|
getQuad()
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
|
|
ignoreAnchorPointForPosition(relative)
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
|
|
isDirty()
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. |
|
isFrameDisplayed(frame)
Returns whether or not a cc.SpriteFrame is being displayed
|
|
return IsOpacityModifyRGB value
|
|
returns whether or not the texture rectangle is rotated
|
|
removeAllChildren(cleanup)
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
|
|
setAnchorPoint(anchor)
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.
|
|
setDirtyRecursively(value)
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
|
|
setOpacityModifyRGB(value)
opacity: conforms to CCRGBAProtocol protocol
|
|
setPosition(pos)
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 )
|
|
setSkewX(sx)
SkewX setter (override cc.Node )
|
|
setSkewY(sy)
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.
|
|
setVertexRect(rect)
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
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));
- Parameters:
- {cc.Sprite} child
- {Number} zOrder
- child's zOrder
- {String} tag
- child's tag
//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}
//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}
//create a sprite with a sprite frame var sprite = cc.Sprite.createWithSpriteFrameName('grossini_dance_01.png');
- Parameters:
- {String} spriteFrame
- name
- Returns:
- {cc.Sprite}
//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}
- Parameters:
- {String|cc.SpriteFrame|cc.SpriteBatchNode|HTMLImageElement|cc.Texture2D} fileName
- sprite construct parameter
- Returns:
- {cc.SpriteFrame}
- Parameters:
- {CanvasContext} ctx
- 2d context of canvas
- Returns:
- {Number}
- Returns:
- {cc.BlendFunc}
- Returns:
- {cc.Color3B}
- Returns:
- {cc.Point}
- Returns:
- {Number}
- Returns:
- {cc.V3F_C4B_T2F_Quad}
- Returns:
- {cc.SpriteBatchNode}
- Parameters:
- {Boolean} pobTextureAtlas
- Returns:
- {cc.TextureAtlas}
- Returns:
- {cc.Rect}
- Parameters:
- {Boolean} relative
- Returns:
- {Boolean}
var mySprite = new cc.Sprite(); mySprite.initWithFile("HelloHTML5World.png",cc.rect(0,0,480,320));
- Parameters:
- {String} filename
- {cc.Rect} rect
- Returns:
- {Boolean}
var spriteFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame("grossini_dance_01.png"); var sprite = new cc.Sprite(); sprite.initWithSpriteFrame(spriteFrame);
- Parameters:
- {cc.SpriteFrame} spriteFrame
- Returns:
- {Boolean}
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}
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}
- Returns:
- {Boolean}
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}
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}
- Parameters:
- {cc.SpriteFrame} frame
- Returns:
- {Boolean}
- Returns:
- {Boolean}
- Returns:
- {Boolean}
- Parameters:
- cleanup
- whether or not cleanup all running actions
- Parameters:
- child
- cleanup
- whether or not cleanup all running actions
- Parameters:
- {cc.Node} child
- {Number} zOrder
- Parameters:
- {cc.Point} anchor
- Parameters:
- {Number} atlasIndex
- Parameters:
- spriteBatchNode
- Parameters:
- {Number} src
- {Number} dst
- Parameters:
- {cc.Color3B} color3
- Parameters:
- {Boolean} bDirty
- Parameters:
- {Boolean} value
- Parameters:
- {cc.SpriteFrame} newFrame
The animation name will be get from the CCAnimationCache
- Parameters:
- animationName
- frameIndex
- Parameters:
- {Boolean} flipX
- Parameters:
- {Boolean} flipY
- Parameters:
- {Number} opacity
- Parameters:
- {Boolean} value
- Parameters:
- {cc.Point} pos
- Parameters:
- {Number} rotation
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
- Parameters:
- {Number} scaleX
- Parameters:
- {Number} scaleY
- Parameters:
- {Number} sx
- SkewX value
- Parameters:
- {Number} sy
- SkewY value
- Parameters:
- {cc.SpriteBatchNode} spriteBatchNode
- Parameters:
- {HTMLImageElement|HTMLCanvasElement|cc.Texture2D} texture
- Parameters:
- {cc.TextureAtlas} textureAtlas
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
- Parameters:
- {Number} vertexZ
- Parameters:
- {Boolean} visible
- Parameters:
- {cc.SpriteBatchNode} batchNode