Sprite Kit物理导致太多抖动

时间:2014-08-14 23:41:51

标签: ios sprite-kit sprite physics

在我的应用程序中,一旦游戏堆叠到一定高度,屏幕就会开始向下移动,以便有更多的空间进行构建。问题在于每次屏幕向下移动时,游戏都会摇晃得太厉害,以至于它们会翻倒。

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    for (UITouch *touch in touches) {
        CGPoint location = [touch locationInNode:self];

        SKSpriteNode *gamePiece = [self pickObject];
        gamePiece.position = location;
        gamePiece.physicsBody.dynamic = NO;

        [self addChild:gamePiece];

        _currentTouch = touch;
        currentGamePiece = gamePiece;

        CGPoint touchLocation = [touch locationInNode:self.scene];

        if(touchLocation.y > 350)
        {
            _bg.position = CGPointMake(_bg.position.x, _bg.position.y-2);
        }
    }
}

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

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

        if ([touch isEqual:_currentTouch])
        {
            currentGamePiece.position = location;
        }

        CGPoint touchLocation = [touch locationInNode:self.scene];

        if(touchLocation.y > 350)
        {
            _bg.position = CGPointMake(_bg.position.x, _bg.position.y-2);
        }
    }
}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    /* Called when a touch begins */
    for (UITouch *touch in touches)
    {
        CGPoint location = [touch locationInNode:self];

        if ([touch isEqual:_currentTouch])
        {
            currentGamePiece.position = location;
            currentGamePiece.physicsBody.dynamic = YES;
        }
    }
}

0 个答案:

没有答案