如何改变碰撞行为以便d跳?
以下是灰球的属性:
func propertIEsGrayBall() { gray = SKShapeNode(circleOfRadius: frame.wIDth / 10 ) gray.physicsBody = SKPhysicsBody(circleOfRadius: frame.wIDth / 10 ) gray.physicsBody?.affectedByGravity = false gray.physicsBody?.dynamic = true gray.physicsBody?.allowsRotation = false gray.physicsBody?.restitution = 1}
以下是红球的属性:
func propertIEsRedBall { let redBall = SKShapeNode(circleOfRadius: self.size.wIDth / 20 redBall.physicsBody = SKPhysicsBody(self.size.wIDth / 20) redBall.physicsBody?.affectedByGravity = false redBall.physicsBody?.dynamic = true redBall.physicsBody?.density = redBall.physicsBody!.density * 0.000001 redBall.physicsBody?.allowsRotation = false redBall.physicsBody?.restitution = 1}
这是我如何移动灰球.
overrIDe func touchesMoved(touches: Set<UItouch>,withEvent event: UIEvent?) { if fingerIsOnGrayBall { let touch = touches.first var position = touch!.locationInVIEw(self.vIEw) position = self.convertPointFromVIEw(position) grayBall.position = position }}
主要编辑
球最初有附件.我删除它们以简化问题.这就是为什么评论可能不会与代码相加.
首先,定义一个变量来存储触摸的位置
class GameScene: SKScene { var point:CGPoint?
然后,从代码中删除以下语句
redBall.physicsBody?.density = redBall.physicsBody!.density * 0.000001
最后,添加以下触摸处理程序
overrIDe func touchesBegan(touches: Set<UItouch>,withEvent event: UIEvent?) { /* Called when a touch begins */ for touch in touches { let location = touch.locationInNode(self) let node = nodeAtPoint(location) if (node.name == "RedBall") { point = location } }}overrIDe func touchesMoved(touches: Set<UItouch>,withEvent event: UIEvent?) { /* Called when a touch begins */ for touch in touches { let location = touch.locationInNode(self) if point != nil { point = location } }}overrIDe func touchesEnded(touches: Set<UItouch>,withEvent event: UIEvent?) { point = nil}overrIDe func update(currentTime: CFTimeInterval) { if let location = point { let dx = location.x - redBall.position.x let dy = location.y - redBall.position.y let vector = CGVector(dx: dx*100,dy: dy*100) redBall.physicsBody?.veLocity = vector }}总结
以上是内存溢出为你收集整理的ios – 拖动对象与Sprite Kit中的另一个对象发生碰撞时不会发生d跳全部内容,希望文章能够帮你解决ios – 拖动对象与Sprite Kit中的另一个对象发生碰撞时不会发生d跳所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)