我试图在 spriteA 和 SpriteB 之间交换位置。他们有父母:parentA 和 parentB。我也在换父母。所以如果我只是在没有动画的情况下交换它就可以了。但是如果我运行 CCMoveTo 动作,精灵会在动作开始时被布置,然后向指定位置移动。我需要的是让他们不要眨眼并从他们的位置移动到指定的位置。父母正在旋转,而孩子没有旋转,因为我使用 child.rotation=-child.parent.protation。这是我的代码
-(void)makeSwapBetweenSelectedShape:(ShapeSprite*)firstShape secondShape:(ShapeSprite*)secondShape{
CGPoint positionOfFirst=[firstShape.parent convertToNodeSpace:firstShape.position];
CGPoint positionOfSecond=secondShape.position;
NSLog(@"POSITION BEFORE 1st %f %f",[firstShape.parent convertToWorldSpace:firstShape.position].x,[firstShape.parent convertToWorldSpace:firstShape.position].y);
NSLog(@"POSITION BEFORE 2nd %f %f",[secondShape.parent convertToWorldSpace:secondShape.position].x,[secondShape.parent convertToWorldSpace:secondShape.position].y);
//swapping parents
CCNode* tempParent=firstShape.parent;
[firstShape removeFromParentAndCleanup:NO];
[secondShape.parent addChild:firstShape];
[firstShape runAction:[CCSequence actions:[CCMoveTo actionWithDuration:1.1 position:positionOfSecond],[CCCallBlockN actionWithBlock:^(CCNode* node){
NSLog(@"POSITION AFTER ANIMATION 1st %f %f ",[node.parent convertToWorldSpace:node.position].x,[node.parent convertToWorldSpace:node.position].y);
}],nil]];
NSLog(@"POSITION ON START 1st %f %f ",[firstShape.parent convertToWorldSpace:firstShape.position].x,[firstShape.parent convertToWorldSpace:firstShape.position].y);
[secondShape removeFromParentAndCleanup:NO];
[tempParent addChild:secondShape];
[secondShape runAction:[CCSequence actions:[CCMoveTo actionWithDuration:1.1 position:selectedShapeStartingPosition],[CCCallBlockN actionWithBlock:^(CCNode* node){
NSLog(@"POSITION AFTER ANIMATION 2st %f %f ",[node.parent convertToWorldSpace:node.position].x,[node.parent convertToWorldSpace:node.position].y);
}],nil]];
NSLog(@"POSITION ON START 2nd %f %f",[secondShape.parent convertToWorldSpace:secondShape.position].x,[secondShape.parent convertToWorldSpace:secondShape.position].y);
}
给我这个日志:
2013-10-30 19:36:54.397 Wheel[1254:a0b] POSITION BEFORE 1st 160.000000 248.000000
2013-10-30 19:36:54.397 Wheel[1254:a0b] POSITION BEFORE 2nd 160.000000 204.000000
2013-10-30 19:36:54.398 Wheel[1254:a0b] POSITION ON START 1st 116.000000 204.000000
2013-10-30 19:36:54.398 Wheel[1254:a0b] POSITION ON START 2nd 204.000000 248.000000
2013-10-30 19:36:55.533 Wheel[1254:a0b] POSITION AFTER ANIMATION 1st 160.000000 204.000000
2013-10-30 19:36:55.534 Wheel[1254:a0b] POSITION AFTER ANIMATION 2st 160.000000 248.000000
编辑:添加 NSLog