如何为具有多个子节点的节点创建 SpriteKit 动画,并将节点的多个部分作为一个组进行动画处理?
我有以下节点结构:
- 鸟有身体、尾巴、头部等的子节点
- 头部有上喙、下喙等子节点
在下面的示例中,我想为整个小鸟制作动画,所有孩子都弯腰捡起种子。在弯腰时,鸟张开嘴吃种子。请注意,喙不是鸟的孩子,而是头节点的孩子。
//body does this action
SKAction* bendDown = [SKAction rotateToAngle:M_PI*0.3 duration:lookUpTiming];
//beak does this action
SKAction* openBeak = [SKAction rotateToAngle:-M_PI*0.175 duration:beakDuration + arc4random()%20/100.0];
//I need both actions to be played together as a group:
SKAction* bendAndOpenBeak = [SKAction group:@[bendDown, openBeak]];
//if I call this, the body will perform both actions.
[self runAction:bendAndOpenBeak completion:^{
}];
这是我可以在头节点上运行以使其子节点执行操作的代码runAction:onChildWithName:
但是,我需要将其作为一个组与主体(父节点的父节点)节点一起运行
-(SKAction*)openBeak
{
float angleUp = -M_PI*0.175;
float duration = beakDuration + arc4random()%20/100.0;
SKAction* rotateUp = [SKAction rotateToAngle:angleUp duration:duration];
rotateUp.timingMode = SKActionTimingEaseOut;
SKAction* rotateDown = [SKAction rotateToAngle:-angleUp duration: duration];
rotateUp.timingMode = SKActionTimingEaseOut;
return [SKAction group:@[[SKAction runAction:rotateUp onChildWithName:@"beakUpper"],
[SKAction runAction:rotateDown onChildWithName:@"beakLower"] ]];
}