Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

share|improve this question
If there's any way to make the question more concise, you'll be far more likely to get an answer. Just a suggestion :) – Byte56 Oct 4 '12 at 23:22
yeah, it was a little long - my first thought was to give as much as possible. – A Devanney Oct 5 '12 at 8:47

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.