gpt4 book ai didi

swift - SpriteKit applyImpulse 崩溃

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

当我尝试在我的节点应用程序上使用 applyImpulse 时崩溃并且我收到此消息:fatal error: unexpectedly found nil while unwrapping an Optional value
(lldb)
这是代码:

    self.character.physicsBody = SKPhysicsBody(rectangleOfSize: character.size)
self.character.physicsBody?.affectedByGravity = true
self.character.physicsBody?.categoryBitMask = PhysicsCategory.PlayerCat
self.character.physicsBody?.contactTestBitMask = PhysicsCategory.ObstaclesCat
self.character.physicsBody?.dynamic = true
self.character.physicsBody?.mass = 5
self.character.physicsBody?.friction = 0.5
self.character.physicsBody?.restitution = 0

还有我的 applyImpulse: character.physicsBody?.applyImpulse(CGVectorMake(0,100))我已经尝试了一些东西,现在我发现问题是 SKPhysicsBody 的大小为零,但为什么呢?即使我尝试手动设置大小也是如此。

最佳答案

这意味着您正在尝试将一个 Action 或物理应用到一个不存在的空节点上,因此它会崩溃。

关于swift - SpriteKit applyImpulse 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30948598/

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