我的游戏是一个侧面滚动器,因此Hero具有恒定的速度,每次更新都会设置为他的速度。当我用几个"盒子组成一个地板时,Hero停在第一个结束而第二个结束的地方。它们具有相同的尺寸且位于同一y轴上,为什么会发生这种情况呢?
物理英雄的身体:
self.physicsBody = SKPhysicsBody(rectangleOfSize: rect.size, center: center)
self.physicsBody?.usesPreciseCollisionDetection = true
self.physicsBody?.allowsRotation = false
self.physicsBody?.restitution = 0
self.physicsBody?.categoryBitMask = Category.Hero
self.physicsBody?.collisionBitMask = Category.Floor | Category.Hero | Category.Glass | Category.Obstacle
self.physicsBody?.contactTestBitMask = Category.Obstacle | Category.Glass | Category.Collision | Category.Doors | Category.EBullet | Category.Enemy | Category.Explosion | Category.Plyuha | Category.Slime
PhysicsBody for obstacle:
self.physicsBody = SKPhysicsBody(rectangleOfSize: size_sprite)
self.physicsBody?.usesPreciseCollisionDetection = true
self.physicsBody?.restitution = 0
self.physicsBody?.allowsRotation = false
self.physicsBody?.pinned = true
self.physicsBody?.categoryBitMask = Category.Obstacle
self.physicsBody?.contactTestBitMask = Category.Bullet | Category.EBullet
self.physicsBody?.collisionBitMask = Category.Hero | Category.Bullet | Category.EBullet
答案 0 :(得分:0)
我会创建一个基于边缘的物理体,它可以拉伸屏幕的长度来模拟地板。这样可以防止玩家停在地板边缘,因为它是一个持续的边缘。然后你可以尝试在玩家面前放置障碍物。
像这样设置物理体:
let startPoint = CGPoint() // fill in the desired x and y for start point
let endPoint = CGPoint() // fill in the desired x and y for start point
self.floor.physicsBody = SKPhysicsBody(edgeFromPoint: CGPoint(x: startPoint.x, y: startPoint.y), toPoint: CGPoint(x: endPoint.x, y: endPoint.y))
对于可能阻止播放器的其他障碍,请通过显示物理实体的实际位置来尝试调试。可能有些东西你并不期望阻止玩家前进。
在viewController中,输入
skView.showsPhysics = true