Take the 2-minute tour ×
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
    
    
add comment

closed as off-topic by concept3d, bummzack, Anko, Trevor Powell, John McDonald Dec 16 '13 at 21:24

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – concept3d, bummzack, Anko, Trevor Powell, John McDonald
If this question can be reworded to fit the rules in the help center, please edit the question.

Browse other questions tagged or ask your own question.