Objective c 如何将两个SKSPRITENODE一起z旋转,就像一个SKSPRITENODE一样?

Objective c 如何将两个SKSPRITENODE一起z旋转,就像一个SKSPRITENODE一样?,objective-c,sprite-kit,skaction,Objective C,Sprite Kit,Skaction,如何将两个SKSpriteNodes组合在一起,以便可以像旋转一个一样对它们进行z旋转?假设一个SKSpriteNode是一根绳子,另一个是连接到绳子末端的球。我怎样才能让他们看起来像是一起荡秋千?要做到这一点,SKAction是什么?有两个选项: 将它们都放在SKNode中,并旋转SKNode(围绕某个锚点) 或者单独旋转它们,然后移动它们,使它们看起来像是一起旋转的 两种选择: 将它们都放在SKNode中,并旋转SKNode(围绕某个锚点) 或者单独旋转它们,然后移动它们,使它们看起来像

如何将两个SKSpriteNodes组合在一起,以便可以像旋转一个一样对它们进行z旋转?假设一个SKSpriteNode是一根绳子,另一个是连接到绳子末端的球。我怎样才能让他们看起来像是一起荡秋千?要做到这一点,SKAction是什么?

有两个选项:

  • 将它们都放在SKNode中,并旋转SKNode(围绕某个锚点)

  • 或者单独旋转它们,然后移动它们,使它们看起来像是一起旋转的

  • 两种选择:

  • 将它们都放在SKNode中,并旋转SKNode(围绕某个锚点)

  • 或者单独旋转它们,然后移动它们,使它们看起来像是一起旋转的


  • 可能不是最优雅的解决方案,但下面是我如何将SKSpritodes添加到SKNode(容器)中的。containerArray包含应添加的节点。newSpriteName(NSString)用于确定精灵的正面还是背面显示

    // Add a container
    _containerNode = [SKNode node]; 
    _containerNode.position = _theParentNodePosition;
    _containerNode.name = @"containerNode";
    [_background addChild:_containerNode];
    
    for (SKNode *aNode in containerArray) {
    
            if (![aNode.name isEqualToString:@"background"] && ![aNode.name isEqualToString:@"title1"] && ![aNode.name isEqualToString:@"title2"]) {
                // Check if "back" sprite should be added or the front face
                if ([[aNode.name substringFromIndex:[aNode.name length] - 1] isEqualToString:@"b"]) {
                    newSpriteName = @"back";
                } else {
                    newSpriteName = aNode.name;
                }
    
                // Prepare the new node
                SKSpriteNode *newNode = [SKSpriteNode spriteNodeWithImageNamed:newSpriteName];
                newNode.name = aNode.name;
                newNode.zPosition = aNode.zPosition;
                newNode.position = CGPointMake(aNode.position.x - _theParentNodePosition.x, aNode.position.y - _theParentNodePosition.y);
    
                // Delete the old node
                SKNode *deleteNode = [_background childNodeWithName:aNode.name];
                [deleteNode removeFromParent];
    
                // Add the new node
                [_containerNode addChild:newNode];
            }
        }
    

    然后按照鼓手的建议进行旋转

    可能不是最优雅的解决方案,但下面是我如何将SKSpritodes添加到SKNode(容器)中的。containerArray包含应添加的节点。newSpriteName(NSString)用于确定精灵的正面还是背面显示

    // Add a container
    _containerNode = [SKNode node]; 
    _containerNode.position = _theParentNodePosition;
    _containerNode.name = @"containerNode";
    [_background addChild:_containerNode];
    
    for (SKNode *aNode in containerArray) {
    
            if (![aNode.name isEqualToString:@"background"] && ![aNode.name isEqualToString:@"title1"] && ![aNode.name isEqualToString:@"title2"]) {
                // Check if "back" sprite should be added or the front face
                if ([[aNode.name substringFromIndex:[aNode.name length] - 1] isEqualToString:@"b"]) {
                    newSpriteName = @"back";
                } else {
                    newSpriteName = aNode.name;
                }
    
                // Prepare the new node
                SKSpriteNode *newNode = [SKSpriteNode spriteNodeWithImageNamed:newSpriteName];
                newNode.name = aNode.name;
                newNode.zPosition = aNode.zPosition;
                newNode.position = CGPointMake(aNode.position.x - _theParentNodePosition.x, aNode.position.y - _theParentNodePosition.y);
    
                // Delete the old node
                SKNode *deleteNode = [_background childNodeWithName:aNode.name];
                [deleteNode removeFromParent];
    
                // Add the new node
                [_containerNode addChild:newNode];
            }
        }
    

    然后按照鼓手的建议进行轮换

    你能给出一个例子,说明如何将两个SKSpritodes嵌套到一个SKNode中吗?更新答案。当然,您必须更新球和绳子的位置,因为现在您必须在容器节点的坐标空间中定义它们。您能否发布一个示例,说明如何将两个SKSpritodes嵌套到一个SKNode中?更新的答案。当然,您必须更新球和绳子的位置,因为现在必须在容器节点的坐标空间中定义它们。