iphone - change parent of a CCSprite in cocos2D -
i'm kind of new in cocos2dm , i'm facing problem can't solve far have 2 sprites (let's call them tables) in layer , touchable, 1 of them has added other sprites, wanna move 1 table one, i'm recognizing objets touch, & moving them around, problem can't change parent other table, tried remove object parent in different ways & add no new parent, doesn't seem work, object duplicated cause it's not being removed, tried remove them when touch it. i'm storing objects in _objectstodrag & calling function in touchbegan:
- (void) lookforobjectwithtouchlocation:(cgpoint)touchlocation { (riccobject *object in _objectstodrag) { if (cgrectcontainspoint(object.boundingbox, touchlocation)) { _selectedobject = object; } } if (_selectedobject) { [self objectselectedwithlocation:touchlocation]; } }
and using _selectedobject move around, problem? should use aributes instead local objects in array?
any welcome thank in advance
to move instance of class derives ccnode (like ccsprite, cclabelttf etc) 1 parent node another, follow process:
// yournode in whatever way fits implementation ... ccnode* nodetomove = yournode; // not cleaning leaves actions running [nodetomove removefromparentandcleanup:no]; // add removed node new parent node [newparentnode addchild:nodetomove];
this process works regardless of how or else store nodes.
note if see nodes being duplicated, either create new node without removing old node or have 2 nodes begin with. in cocos2d, ccnode can have 1 parent , trying add node has parent node prompt error message. if experience duplicated nodes respectively removing node parent still keeps on screen try find cause first. doesn't happen under normal circumstances, except when create multiple versions of same node.
Comments
Post a Comment