Ios 用轻扫拆分SKTextureNode

Ios 用轻扫拆分SKTextureNode,ios,sprite-kit,sprite,skspritenode,Ios,Sprite Kit,Sprite,Skspritenode,我试着用刷子的姿势把SKTextureNode分成几块。我有进出的坐标 如何使用此方法分割节点?在这种情况下,有一种与SKTexture关联的方法可以提供帮助 [SKTexture textureWithRect:someRect inTexture:someTexture]; 通过基于坐标计算两个矩形,并将其指定给两个SKSpriteNode对象,可以使用此方法 但是,这只能用于生成相关纹理的矩形剪切 另外,请查看。有一个与SKTexture相关联的方法在本例中可能会有所帮助 [SKText

我试着用刷子的姿势把SKTextureNode分成几块。我有进出的坐标


如何使用此方法分割节点?

在这种情况下,有一种与SKTexture关联的方法可以提供帮助

[SKTexture textureWithRect:someRect inTexture:someTexture];
通过基于坐标计算两个矩形,并将其指定给两个SKSpriteNode对象,可以使用此方法

但是,这只能用于生成相关纹理的矩形剪切


另外,请查看。

有一个与SKTexture相关联的方法在本例中可能会有所帮助

[SKTexture textureWithRect:someRect inTexture:someTexture];
通过基于坐标计算两个矩形,并将其指定给两个SKSpriteNode对象,可以使用此方法

但是,这只能用于生成相关纹理的矩形剪切


另外,看看。

我建议使用SKPhysicsJointFixed连接两个SKSpritEndodes以形成一个对象。当用户在对象上滑动时,您可以通过移除关节将其拆分,并应用脉冲将碎片发送到相反方向。以下是连接两个节点的方法:

- (void) connectNode1:(SKSpriteNode *)node1 toNode2:(SKSpriteNode *)node2
{
    CGPoint midPoint = CGPointMake((node1.position.x + node2.position.x)/2,
                                   (node1.position.y + node2.position.y)/2);

    SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
                                                               bodyB:node2.physicsBody
                                                              anchor:midPoint];
    [self.physicsWorld addJoint:joint];
}
下面是一个例子,演示了如何在物体被触摸时分割它。这应该替换为刷卡处理程序

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        // Determine which node was touched
        SKNode *touchedObject = [self nodeAtPoint:location];

        if (touchedObject == self) continue;

        // Check if node is connected
        if ([touchedObject.physicsBody.joints count]) {
            SKPhysicsJointFixed *joint = [touchedObject.physicsBody.joints firstObject];
            SKSpriteNode *node2 = (SKSpriteNode *)(touchedObject.physicsBody == joint.bodyA ?
                            joint.bodyB.node : joint.bodyA.node);

            [self.physicsWorld removeJoint:joint];
            CGFloat dx = touchedObject.position.x - node2.position.x;
            CGFloat dy = touchedObject.position.y - node2.position.y;

            CGFloat magnitude = sqrtf(dx*dx+dy*dy);

            // unit vector
            dx /= magnitude;
            dy /= magnitude;

            // send nodes in opposite directions
            [touchedObject.physicsBody applyImpulse:CGVectorMake(dx*20, dy*20)];
            [node2.physicsBody applyImpulse:CGVectorMake(-dx*20, -dy*20)];
        }
    }
}

我建议使用skphysicjointfixed连接两个SKSpriteNodes以形成一个对象。当用户在对象上滑动时,您可以通过移除关节将其拆分,并应用脉冲将碎片发送到相反方向。以下是连接两个节点的方法:

- (void) connectNode1:(SKSpriteNode *)node1 toNode2:(SKSpriteNode *)node2
{
    CGPoint midPoint = CGPointMake((node1.position.x + node2.position.x)/2,
                                   (node1.position.y + node2.position.y)/2);

    SKPhysicsJointFixed *joint = [SKPhysicsJointFixed jointWithBodyA:node1.physicsBody
                                                               bodyB:node2.physicsBody
                                                              anchor:midPoint];
    [self.physicsWorld addJoint:joint];
}
下面是一个例子,演示了如何在物体被触摸时分割它。这应该替换为刷卡处理程序

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */

    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        // Determine which node was touched
        SKNode *touchedObject = [self nodeAtPoint:location];

        if (touchedObject == self) continue;

        // Check if node is connected
        if ([touchedObject.physicsBody.joints count]) {
            SKPhysicsJointFixed *joint = [touchedObject.physicsBody.joints firstObject];
            SKSpriteNode *node2 = (SKSpriteNode *)(touchedObject.physicsBody == joint.bodyA ?
                            joint.bodyB.node : joint.bodyA.node);

            [self.physicsWorld removeJoint:joint];
            CGFloat dx = touchedObject.position.x - node2.position.x;
            CGFloat dy = touchedObject.position.y - node2.position.y;

            CGFloat magnitude = sqrtf(dx*dx+dy*dy);

            // unit vector
            dx /= magnitude;
            dy /= magnitude;

            // send nodes in opposite directions
            [touchedObject.physicsBody applyImpulse:CGVectorMake(dx*20, dy*20)];
            [node2.physicsBody applyImpulse:CGVectorMake(-dx*20, -dy*20)];
        }
    }
}

什么是SKTextureNode?在苹果的文档中找不到。这是iOSE的精灵套件扩展。你在尝试制作一款类似水果忍者的游戏吗?不太像,但精灵需要被切割:切割成多少块?什么是SKTextureNode?在苹果的文档中找不到。这是iOSE的精灵套件扩展。你在尝试制作一款类似水果忍者的游戏吗?不太像,但精灵需要被切割:切割成多少块?我需要将其拆分,而不仅仅是使用rect。在任何方向,比如水果忍者。我需要把它分开,而不仅仅是用rect。在任何方向,比如水果忍者。