import SpriteKitclass GameScene: SKScene { //Rectangle Skeletions var leftWallRect = CGRect(x: 0,y: 0,wIDth: 40,height: 1000) var ball = SKShapeNode(circleOfRadius: 25); overrIDe func dIDMovetoVIEw(vIEw: SKVIEw) { // Declare the Sprites in your scene var ball = SKShapeNode(circleOfRadius: 25); let leftWall = SKShapeNode(rect: leftWallRect); let rightWall = SKShapeNode(rect: leftWallRect); let pin = SKSpriteNode(imagenamed: "pin"); // Ball PropertIEs ball.strokecolor = UIcolor.blackcolor() ball.fillcolor = UIcolor.redcolor() ball.position = CGPointMake(self.frame.wIDth / 2,self.frame.height / 4 - 100 ) self.addChild(ball) // left Wall PropertIEs leftWall.fillcolor = UIcolor.purplecolor() leftWall.strokecolor = UIcolor.blackcolor() leftWall.position = CGPointMake(self.frame.size.wIDth / 3 - 45,self.frame.size.height / 2 - 400) self.addChild(leftWall) //Right Wall PropertIEs rightWall.fillcolor = UIcolor.purplecolor() rightWall.strokecolor = UIcolor.blackcolor() rightWall.position = CGPointMake(self.frame.size.wIDth / 2 + 175,self.frame.size.height / 2 - 400) self.addChild(rightWall) } overrIDe func touchesBegan(touches: Set<NSObject>,withEvent event: UIEvent) { /* Called when a touch begins */ let touch = touches.first as! UItouch let touchLocation = touch.locationInNode(self) if touchLocation == ball.position{ ball.position = touchLocation println("touches"); } } overrIDe func update(currentTime: CFTimeInterval) { /* Called before each frame is rendered */ }}解决方法 大笑哇,这是一个有趣的,如果touchLocation == ball.position我会留下深刻的印象,如果你可以击中你的球的确切像素位置.你想要的是这个:
let touch = touches.first as! UItouchlet touchLocation = touch.locationInNode(self)let touchednode = self.nodeAtPoint(touchLocation)if touchednode == ball{...
但就个人而言,我要做的是制作SKSpriteNode的子类,并在这个孩子的触摸程序中做你的球的触摸代码
总结以上是内存溢出为你收集整理的Swift Sprite Kit开始触摸功能全部内容,希望文章能够帮你解决Swift Sprite Kit开始触摸功能所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)