I'm stuck with something in Cocos2dx ...
When i copy my class that inherits CCNode, i get a shallow copy of my class but the base type seem to still point to the original node address. We dont seem to get a deep clone of any object that inherits CCNode, any ideas anyone?
Basically i have....
GameItem* pTemp = new GameItem(*_actualItem);
// loops through all the blocks in gameitem and updates their position
pTemp->moveDown();
// if in boundary or collision etc...
if (_gameBoard->isValidMove(pTemp))
{
_actualItem = pTemp;
// display the position
CCLog("pos (1) --- (X : %d,Y : %d)", _actualItem->getGridX(),_actualItem->getGridY());
}
Then doesn't work, because the gameitem inherits CCNode and has the collection of another class that also inherits CCNode with is a pointer.
its just creating a shallow copy and when you look at children of the gameitem node in the copy, it still just points to the original base type?
class GameItem : public CCNode {
// maps to the actual grid position of the shape
CCPoint* _rawPosition;
// tracks the current grid position
int _gridX, _gridY;
// tracks the change if the item has moved
CCPoint _offset;
public:
//constructors
GameItem& operator=(const GameItem& item);
GameItem(Shape shape);
}
then in the implementation....
GameItem& GameItem::operator=(const GameItem& item)
{
_gridX = item.getGridX();
_gridY = item.getGridY();
_offset = item.getOffSet();
_rawPosition = item.getRawPosition();
// how do i copy the node?
return *this;
}
Any ideas are welcome at this point!!
thanks