gpt4 book ai didi

ios - Sprite Kit - SKShapeNode 在碰撞后消失

转载 作者:行者123 更新时间:2023-11-29 02:52:11 26 4
gpt4 key购买 nike

我创建了一个球来绕着屏幕弹跳,但是球在碰到屏幕边界的那一刻就消失了

这是我当前的代码

 override func didMoveToView(view: SKView) {
/* Setup your scene here */
self.backgroundColor = SKColor.whiteColor()
self.physicsWorld.gravity = CGVectorMake(0, 0)

self.physicsBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
self.physicsBody.restitution = 0.0
self.physicsBody.angularDamping = 0.0
self.physicsBody.friction = 0.0
self.physicsBody.dynamic = false
self.physicsBody.categoryBitMask = borderCategory
self.physicsBody.collisionBitMask = bCategory

self.setUpBall()
}

func setUpBall() {
ball = SKSpriteNode(imageNamed: "Ball")

ball.physicsBody = SKPhysicsBody(circleOfRadius: ball.frame.width/2)
ball.physicsBody.restitution = 0.8
ball.physicsBody.angularDamping = 0.5
ball.physicsBody.linearDamping = 0.5
ball.physicsBody.allowsRotation = false
ball.physicsBody.usesPreciseCollisionDetection = true
ball.physicsBody.friction = 0.0
ball.physicsBody.dynamic = true
ball.physicsBody.categoryBitMask = bCategory
ball.physicsBody.categoryBitMask = borderCategory

ball.position = CGPointMake(self.frame.width/2, self.frame.height/2)
self.addChild(ball)

ball.physicsBody.applyImpulse(CGVectorMake(15, 20))
}

最佳答案

ball.physicsBody.categoryBitMask = bCategory
ball.physicsBody.categoryBitMask = borderCategory

你不是说

ball.physicsBody.collisionBitMask = borderCategory

?

关于ios - Sprite Kit - SKShapeNode 在碰撞后消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24365785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com