Grant Cermak
Grant Cermak

Reputation: 1818

When should I change the parent of a CCNode in cocos2d?

I have a CCLayoutBox at the bottom of a scene which is the parent for several CCSprites. These sprites represent the game tokens that the player can play on the board.

On touchBegan where the player has touched a game token, I start updating the position of the the token relative to the CCLayoutBox as the touchMoved event fires.

The question I have is whether this is the correct thing to do? Should I immediately remove the CCSprite from the CCLayoutBox when the player "picks up" the token? Should I re-parent the node to the board when the player drops the token in a valid location?

Upvotes: 0

Views: 69

Answers (1)

Kalvin
Kalvin

Reputation: 71

It's not wrong to use using the CCLayoutBox as your position reference but it depends on how you use your board and CCLayoutBox.

If your board is static there is no problem at all, but if you need to move along the game to another point of the board for example you're gonna have some problems with the tokens already positioned in the board.

If the player can move along the board, you can remove the token from the CCLayoutBox when the player drops the token in the board and add a new token with the board as parent. This will help since the tokens in the board will move along.

Hope it helps :)

Upvotes: 1

Related Questions