ios - 碰撞处理在 iOS 13 中不起作用
问题描述
我目前正在尝试与 Xcode 11 (iOS 13) 中的碰撞处理相处。我的问题是,甚至 Apple 的示例代码似乎都不适合我。(https://developer.apple.com/documentation/spritekit/skphysicsbody/about_collisions_and_contacts)
苹果的示例代码:
import SpriteKit
import GameplayKit
class GameScene: SKScene {
override func didMove(to view: SKView) {
let ballRadius: CGFloat = 20
let redBall = SKShapeNode(circleOfRadius: ballRadius)
redBall.fillColor = .red
redBall.position = CGPoint(x: 280, y: 320)
redBall.physicsBody = SKPhysicsBody(circleOfRadius: ballRadius)
let blueBall = SKShapeNode(circleOfRadius: ballRadius)
blueBall.fillColor = .blue
blueBall.position = CGPoint(x: 360, y: 320)
blueBall.physicsBody = SKPhysicsBody(circleOfRadius: ballRadius)
var splinePoints = [CGPoint(x: 0, y: 300),
CGPoint(x: 100, y: 50),
CGPoint(x: 400, y: 110),
CGPoint(x: 640, y: 20)]
let ground = SKShapeNode(splinePoints: &splinePoints,
count: splinePoints.count)
ground.physicsBody = SKPhysicsBody(edgeChainFrom: ground.path!)
ground.physicsBody?.restitution = 0.75
redBall.physicsBody?.collisionBitMask = 0b0001
blueBall.physicsBody?.collisionBitMask = 0b0010
ground.physicsBody?.categoryBitMask = 0b0001
}
override func update(_ currentTime: TimeInterval) {
// Called before each frame is rendered
}
}
当我运行代码时,两个球都与曲线碰撞。
是我做错了什么,还是 SpriteKit 中有我不知道的更新功能?
谢谢你的帮助!
解决方案
我创建了一个新的 Xcode 项目并粘贴了问题中的代码,它最终奏效了。
我不知道是哪个项目文件导致了这个问题。
谢谢您的帮助!
推荐阅读
- swift - 如何添加UIButton的渐变阴影
- php - Laravel HasManyThrough 与 onetomany 和 onetoone
- java - 如何以编程方式获取 JPA API 版本?
- python - 元素矩阵乘法可能通过共享内存获得性能提升?
- createjs - EaselJS 的 getObjectsUnderPoint (MouseMovement) 的高效方法
- android - 营养历史数据始终从 Android 上的 Google Fit 返回第一项
- javascript - 如何确保在事件侦听器触发后加载 Javascript 文件?
- kubernetes - Vault 颁发者证书不包括中间链
- r - 在 R 的逻辑回归模型中将虚拟变量的组合创建为单个变量
- tradingview-api - Pine Script 如何将输入放入样式