I have an object that inherited from CCSprite. I want from inside this object to change the image.
How do I change the image (sprite) without creating a new CCSprite object in Cocos2d-X?
Thanks, Adrian.
You can use a Texture2D object for many sprites. Only the contents inside rect of this texture will be applied for this sprite. True if the sprite is initialized properly, false otherwise. Initializes a sprite with a texture and a rect in points, optionally rotated. After initialization, the offset will be (0,0). This is the designated initializer.
A SpriteFrame object. It should includes a valid texture and a rect. True if the sprite is initialized properly, false otherwise. Initializes a sprite with an sprite frame name. A SpriteFrame will be fetched from the SpriteFrameCache by name.
The Blending function property belongs to SpriteBatchNode, so you can't individually set the blending function property. ParallaxNode is not supported, but can be simulated with a "proxy" sprite. Sprites can only have other Sprites (or subclasses of Sprite) as children.
Basic Cocos2d-x Concepts Main Components Director Scenes and the Scene graph Sprites Actions Sequences and Spawns
mySprite->setTexture(CCTextureCache::sharedTextureCache()->addImage("newImage.png"));
No need to alter your custom class.. Hope this helps.. :)
Works for me:
mySprite->setDisplayFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("frame_name"));
Before you need to load you sprites in cache:
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("sprite_atlas.plist");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With