gpt4 book ai didi

ios - SpriteKit : Rotating SKNode falls off screen when adding another physics body

转载 作者:行者123 更新时间:2023-11-28 09:09:03 24 4
gpt4 key购买 nike

下面的代码使 rotateLayer 物理体在几秒钟后从屏幕上掉下来。但是,注释掉圆形物理体会使 rotateLayer 保持在屏幕上。不可以给一个节点添加物理体,然后旋转父节点吗?从概念上讲,目标是围绕一个固定点旋转圆圈,as described here ,但将物理体附加到圆上,同时还通过角速度而不是 zRotation 来控制旋转。

let size = CGSize(width: 10, height: 250)
rotateLayer = SKNode()
gameLayer.addChild(rotateLayer)

let circleSize = CGSize(width: 10, height: 10)
let circle = SKSpriteNode(color: SKColor.whiteColor(), size: circleSize)
circle.position = CGPoint(x: 0, y: size.height/2 + circleSize.height/2)
circle.physicsBody = SKPhysicsBody(rectangleOfSize: circleSize)
circle.physicsBody?.affectedByGravity = false
circle.physicsBody?.friction = 0
circle.physicsBody?.linearDamping = 0
circle.physicsBody?.angularDamping = 0
circle.physicsBody?.collisionBitMask = 0
circle.physicsBody?.dynamic = false

rotateLayer.addChild(circle)

rotateLayer.physicsBody = SKPhysicsBody(rectangleOfSize: size)
rotateLayer.physicsBody?.affectedByGravity = false
rotateLayer.physicsBody?.friction = 0
rotateLayer.physicsBody?.linearDamping = 0
rotateLayer.physicsBody?.angularDamping = 0
rotateLayer.physicsBody?.angularVelocity = -3.0

最佳答案

添加 rotateLayer.collisionBitMask = 0 解决了这个问题。不知道为什么。

关于ios - SpriteKit : Rotating SKNode falls off screen when adding another physics body,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29932492/

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