在SpriteKit上取消激活物理

时间:2014-06-18 11:43:09

标签: android ios objective-c sprite-kit game-physics

我想暂停一下节点的物理效果。请帮我解决这个问题。

  SKSpriteNode * node = [SKSpriteNode spriteNodeWithImageNamed:@"blade.png"];
    node.size = CGSizeMake(30, 30);
    node.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:node.size];
    node.physicsBody.dynamic = YES;
    node.physicsBody.collisionBitMask = CharacterCategory;
    node.physicsBody.categoryBitMask = ObjectCategory;
    node.physicsBody.contactTestBitMask = CharacterCategory;
    node.position = nd.Position;
    node.physicsBody.mass = 10000;
    SKAction * actfadein = [SKAction fadeInWithDuration:nd.FadeInDuration];
    SKAction * actfadeout = [SKAction fadeOutWithDuration:nd.FadeOutDuration];
    SKAction * wait = [SKAction waitForDuration:3];
    SKAction * removephy = [SKAction runBlock:^(void){
        // i tried to removeFromParent but it never comes back
    }];
    SKAction * activatephy = [SKAction runBlock:^(void){
        //[self addChild:node];
    }];
    SKAction * myActions = [SKAction sequence:@[actfadeout,removephy,wait,activatephy,actfadein]];
    [node runAction:[SKAction repeatActionForever:myActions]];
    [FadeObjects addChild:node];

2 个答案:

答案 0 :(得分:2)

只需将physicsBody的{​​{1}}属性设置为nil即可。如果您以后需要再次应用物理,只需指定另一个SKSpriteNode

答案 1 :(得分:-1)

设置:

node.physicsBody.dynamic = NO;