tried it… not happening … exactly what i want is to swap two class objects … the sprite property of one object to point to another objects sprite… i hope i making it clear… thanks fradow for quick reply
trying to do this, obj[0]'s sprite must contain obj[1]'s sprite , tried that std::swap template , not working … to verify tried printing out the addresses …
So you have tried something like
Sprite* temp = obj[0]->sprite;
obj[0]->sprite = obj[1]->sprite;
obj[1]->sprite = temp;
and afterwards what doesn’t happen?
Remember this only swaps the references from the obj - noting will happen on screen (i.e. the location, size, rotation etc, of each sprite will be unchanged, unless your code does something to change that)
Your CCLOG have a strange syntax, and I’m almost sure it’s wrong (displaying the address of the pointer, which is never going to change, not the address of what the pointer points to, which is the relevant value). The format to see which address a pointer points to is %p.
What is the result of this code ?
CCLOG(" before swap target %p this %p" , targetTile->tileSprite , this->tileSprite));
std::swap(this->tileSprite, targetTile->tileSprite);
CCLOG(" after swap target %p this %p" , targetTile->tileSprite , this->tileSprite));
fradow thanks!!! i was printing it wrong … i still have to figure out the other and the actual mistake i’m making cos of which the values are not getting reflected on the swapped objects. I’ll keep you updatedif they dont close this post…