0

i have 2 layers and on ccTouchMoves event i have to destroy and recreate sprite to move from 1st layer to 2nd

i did this something like that

-(void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
            sprite = [CCSprite spriteWithFile:@"file.png"];
            [[self parent] addChild: sprite]
            if (sprite)
            {
                [sprite ccTouchBegan:touch withEvent:event];
            //  [character ccTouchMoved:touch withEvent:event];
            }
            [self removeFromParentAndCleanup:true];
}

sprite created and called method ccTouchBegan but after that method everything is terminate how to call ccTouchMoved and ccTouchEnd just like simple touch event

4

1 回答 1

0

如果它是同一个精灵,为什么要销毁并重新创建它?您可以继续使用相同的精灵。在Kobold2D中,我在 CCNode 类别中添加了此方法,以将节点的所有权从当前父节点转移到不同的父节点:

-(void) transferToNode:(CCNode*)targetNode
{
    CCNode* selfNode = [self retain];
    [self removeFromParentAndCleanup:NO];
    [targetNode addChild:selfNode z:selfNode.zOrder tag:selfNode.tag];
    [selfNode release];
}

重要的部分是从其当前父节点中删除节点(您的精灵)而不进行清理,以便调度程序和操作继续运行。然后只需将其作为子节点添加到不同的节点(您的第二层)。

于 2012-12-22T12:00:21.610 回答