我正在开发我的第一个快速iOS精灵套件项目,但我遇到了一个我无法找到解决方案的问题。我的目标是让一个球落在一个移动的平台上,球和平台都会在接触时停止。
我遇到的问题是,当代码识别出它们处于联系状态并使它们停止时,平台和球之间始终存在差距。见附图:
球:
{!! Form::label('businesslocation_id', 'Business location:') !!}
<select class="form-control" id="businesslocation_id" name="businesslocation_id">
@foreach($businesslocations as $key => $businesslocation)
<option value="{{$businesslocation->id}}">{{$businesslocation->address_1}} {{$businesslocation->address_2}} {{$businesslocation->city}}</option>
@endforeach
</select>
平台:
//Ball Node
func createPlayer() -> SKNode {
let playerNode = SKNode()
playerNode.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.25)
let sprite = SKSpriteNode(imageNamed: "ball")
sprite.setScale(scaleFactor)
playerNode.addChild(sprite)
playerNode.physicsBody = SKPhysicsBody(circleOfRadius: sprite.size.width / 2)
playerNode.physicsBody?.dynamic = false
playerNode.physicsBody?.allowsRotation = false
playerNode.physicsBody?.restitution = 0.0
playerNode.physicsBody?.friction = 0.0
playerNode.physicsBody?.angularDamping = 0.0
playerNode.physicsBody?.linearDamping = 0.0
playerNode.physicsBody?.usesPreciseCollisionDetection = true
playerNode.physicsBody?.categoryBitMask = CollisionCategoryBitmask.Player
playerNode.physicsBody?.collisionBitMask = 0
playerNode.physicsBody?.contactTestBitMask = CollisionCategoryBitmask.Platform | CollisionCategoryBitmask.Vortex
return playerNode
didBeginContact:
//Platform
sprite = SKSpriteNode(imageNamed: "platform")
let node = PlatformNode()
let thePosition = CGPoint(x: position.x * scaleFactor - (sprite.size.width / 1.999), y: position.y + (self.size.height * 0.50))
sprite.setScale(scaleFactor)
node.addChild(sprite)
node.physicsBody?.usesPreciseCollisionDetection = true
node.physicsBody = SKPhysicsBody(rectangleOfSize: sprite.size)
node.physicsBody?.dynamic = false
node.physicsBody?.categoryBitMask = CollisionCategoryBitmask.Platform
node.physicsBody?.collisionBitMask = 0
return node
答案 0 :(得分:0)
我怀疑您可以在连接对象之前等待物理模拟完成后(对于当前帧)来解决此问题。一种方法是在球与didBeginContact
中的平台接触时设置一个标记,然后用didSimulatePhysics
中的一个关节连接两个实体。