检测Sprite是否已通过“虚构”行

时间:2018-08-21 05:37:33

标签: swift sprite-kit

到目前为止,我已经创建了一个函数,该函数生成一个球并基于冲动来启动它。我的目标是稍后在任意位置启动它,但是,现在,我只想将该启动点放在我设置的屏幕上某个地方,我的功能如下,

 func SpawnBall() {
        let ball = SKSpriteNode(imageNamed: "Soccer")
        ball.physicsBody = SKPhysicsBody(texture:ball.texture!,size:ball.texture!.size())
       ball.physicsBody?.restitution = 1
        ball.physicsBody?.isDynamic = true
    //    ball.position = CGPoint(x: -150, y: 320)
        self.addChild(ball)
        ball.position = CGPoint(x: -150, y: 320)
        ball.physicsBody?.applyImpulse(CGVector(dx: 500, dy: 1000))
        ball.physicsBody?.collisionBitMask = netCategory
        ball.physicsBody?.categoryBitMask = BallCategory
        self.physicsBody = SKPhysicsBody(edgeLoopFrom: self.frame)
        self.physicsBody?.restitution = 1
        self.physicsBody?.friction = 0
}

....

但是,我的问题是,我想知道球是否已通过特定线或假想线。所以我只是检查ball.position.x,但是由于某种原因它不会更新,我知道我已经在函数中进行了设置,但是为什么当施加脉冲时位置不会更新?

0 个答案:

没有答案
相关问题