Spritekit节点在移动时抖动....为什么?

时间:2014-12-30 16:53:43

标签: ios objective-c sprite-kit

我试图使用SKAction移动节点,但每当我添加节点并移动它时,它就像疯了一样开始在y轴上上下抖动!

有什么想法吗?

我尝试过使用MoveToY,MoveTo等等。没有运气不确定是什么原因导致抖动..

谢谢..

-(void)addEnemy{
    enemy = [SKSpriteNode spriteNodeWithImageNamed:@"enemy"];
    enemy.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(40, 40)];
    enemy.physicsBody.dynamic = YES;
    enemy.physicsBody.usesPreciseCollisionDetection = YES;
    enemy.physicsBody.categoryBitMask = enemyHitCatagory;
    enemy.physicsBody.contactTestBitMask = bulletHitCatagory;
    enemy.physicsBody.collisionBitMask = bulletHitCatagory;

    enemy.position = CGPointMake(random() % 300, CGRectGetMaxY(self.frame));
    enemy.size = CGSizeMake(40, 40);
    enemy.zPosition = 5;
    SKAction *attack = [SKAction moveTo:(CGPointMake(20, 300)) duration:(3)];
    [enemy runAction:[SKAction repeatAction:attack count:1]];


    [self addChild:enemy];

}

1 个答案:

答案 0 :(得分:1)

这种情况正在发生,因为物理机构正在发生碰撞。默认情况下,SKPhysicsBody的{​​{1}}为restitution,使其有点弹性。设置0.2并对你的敌人碰撞的物理身体做同样的事情,可以解决你所看到的抖动。