sprite->setTexture(sprite1->getTexture()) works on HelloWorld::init() but not on HelloWorld::update()...

… but when I add this lines below on the HelloWorld::update() too => it works:

sprite = CCSprite::create(“HelloWorld.png”);
sprite1 = CCSprite::create(“HelloWorld.png”);

My question is:
I do not understand why it works when I add this lines above again. It seems something is lost between first draw on HelloWorld::init() and redraw on HelloWorld::update().

Background:
CCSprite sprite;
CCSprite
sprite1;
been declared on file ‘HelloWorldScene.h’ (class class HelloWorld)

and initialised on the overwritten ctor: HelloWorld::HelloWorld like this lines below on file ‘HelloWorldScene.cpp’
sprite = CCSprite::create(“HelloWorld.png”);
sprite1 = CCSprite::create(“HelloWorld.png”);

When you say working/not working are you getting an error?

Are you sure your sprite references are still OK in the update function?

The fact that you have to recreate both sprites in the update would suggest that 1 or both is dereferenced.

Adam Reed wrote:

When you say working/not working are you getting an error?
Yes I got an error message. Sorry I can’t say the error text at the moment (I am not at home).

>

Are you sure your sprite references are still OK in the update function?
I think it should because I called the CCSprite::create() method on the CCHelloWorld::ctor.

>

The fact that you have to recreate both sprites in the update would suggest that 1 or both is dereferenced.
Yes. But I have no idea why it should derefereced. Maybe a hint can help me to find the source part which dereference this sprites.
For me it looks like there is a bug on the cocos2dx.

Have you tried it on your own source too?

Your code does not mention but are you adding the sprite to your main scene layer i.e. this~~>addChild; ?
Maybe you could add the sprites with a TAG ) and then get them out using this~~>getChildWithTag(TAG).
Even if you lose your reference to the sprite, it will still be in layer child list.

Hello Adam,

Of course I use this->addChild(sprite, 0);
But I thought the second parameter is for the Z-Order? Not realy usable like a ‘name’.

Sorry, it would be addChild(sprite, 0, TAG)

You say of course but you could add the sprite to a another layer rather than this.

Hello Adam,

Lot of thanks for your helping hand.
The prob was: I forgot to add some sprites to the layer. After adding it works correct.

Thanks
P.E.