Add a sprite to a layer having some texture. (created using Sprite::create(something.png))
Now, how to change the texture of a sprite but to put a nice fading in effect with it
Note: fading in effect is easy if I am creating a sprite but how to do it for the texture that is now added.
To explain in other words:
I have a sprite. Now, I want to change it texture while applying the fadingIn effect at the same time…
Is it possible? I doubt actually!!
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("texture.plist");
auto textureA = SpriteFrameCache::getInstance()->getSpriteFrameByName("textureA.png");
auto textureB = SpriteFrameCache::getInstance()->getSpriteFrameByName("textureB.png");
auto sp = Sprite::create();
sp->setSpriteFrame(textureA);
sp->setSpriteFrame(textureB);
Ohk, I see setSpriteFrame… I’ll try this…
but what how to set thsi fading effect? I mean setSpriteFrame will just change the texture and there is not argument for any effect in that…
Are you talking about…
auto spriteK = Sprite::create(“1.png”);
spriteK-> setPosition(Vec2(100,100));
this->addChild(spriteK);
//Now…
auto myAction = FadeIn(0.5);
spriteK-> setSpriteFrame(“2.png”);
spriteK->runAction(myAction);
So, is this the way you’re suggesting?
Also, what is the difference between setting a texture and setting a frame
Setting a texture sets the total pixel information stored in a texture.
Setting a frame only sets the information used in the rectangle defined in the sprite, but still storing the complete texture information… The rectangle/frame is able to set/render a small part of the texture.