使对象粘在SpriteKit屏幕的顶部

时间:2014-11-12 08:29:52

标签: ios sprite-kit

如何停止从屏幕底部移动到顶部的对象。对象应该坚持到顶部。以下是该对象的代码:

    SKSpriteNode* ball = [SKSpriteNode spriteNodeWithImageNamed: @"ball.png"];
    ball.name = ballCategoryName;
    ball.position = CGPointMake(self.frame.size.width/3, self.frame.size.height/3);
    [self addChild:ball];

    ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:ball.frame.size.width/2];

    ball.physicsBody.friction = 1.0f;

    ball.physicsBody.restitution = 1.0f;

    ball.physicsBody.linearDamping = 0.0f;

    ball.physicsBody.allowsRotation = YES;


    [ball.physicsBody applyImpulse:CGVectorMake(0.0f, -10.0f)];

1 个答案:

答案 0 :(得分:1)

- (void) checkPosition
{
    if (ball.position.y > self.height.size) {
        ball.position.y = ball.position.y - 1;
    }
}

- (void)update:(NSTimeInterval)currentTime
{
    [self checkPosition];    //update tests rough 60 times per sec.
}