0
我会开始接触(它会带你到一个单独的场景),但我也有一个SKSpriteNode设置,例如当你触摸它时,你会去一个不同的场景。这是我的代码,用于查找settingsPage
节点是否已被触摸。TouchedEarth TouchesBegan - Swift iOS SpriteKit
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
if (settingsPage .containsPoint(touchLocation))
{
println("Going to Settings")
settingsScene()
}
}
由于某些原因触摸开始优先于touchesEnded。
是他们找到这个或?
override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
/* Called when a touch begins */
let touch = touches.anyObject() as UITouch
let touchLocation = touch.locationInNode(self)
if (settingsPage .containsPoint(touchLocation))
{
println("Going to Settings")
settingsScene()
}
game1 = 1
if (Menu == 0) {
movingObjects.speed = 1
birdPhysics()
let action = SKAction.rotateByAngle(CGFloat(-M_PI), duration:0.8)
bird.runAction(SKAction.repeatActionForever(action))
taptoflap.removeFromParent()
started = 1
if (powerupStatus == 1) {
PUten = NSTimer.scheduledTimerWithTimeInterval(8, target: self, selector: Selector("plustenSpawn"), userInfo: nil, repeats: true)
}
}
if (gameOver == 0) {
bird.physicsBody?.velocity = CGVectorMake(0, 0)
bird.physicsBody?.applyImpulse(CGVectorMake(0, impulse))
// Add 1 to the currentTouches
currentTouches++
Menu = 1
} else {
scoreLabel.text = "0"
bird.physicsBody?.velocity = CGVectorMake(0,0)
settingsPage.removeFromParent()
gameOver = 0
movingObjects.speed = 1
// Animate Bird
var animation = SKAction.animateWithTextures([birdTexture, birdTexture2, birdTexture3, birdTexture4], timePerFrame: 0.08)
var makeBirdFlap = SKAction.repeatActionForever(animation)
bird.runAction(makeBirdFlap)
bird.texture = birdDeadTexture
normButton.removeFromSuperview()
highscoreClassic.removeFromParent()
let height = self.frame.size.height
let width = self.frame.size.width
var speedGameScene: SpeedGameScene = SpeedGameScene(size: CGSizeMake(width, height))
var spriteView: SKView = self.view as SKView!
var trans:SKTransition = SKTransition.doorsCloseHorizontalWithDuration(0.7)
spriteView.presentScene(speedGameScene, transition: trans)
}
}
'touchesBegan'将始终在'touchesEnded'之前执行。我不明白你的问题? – rakeshbs 2015-02-10 00:41:39
那么我有一个节点,在我的场景中,当我触摸那个节点,我想导航到另一个场景,但事情是节点只显示游戏结束时,但touchesBegan会再次运行游戏(如果屏幕被挖掘)?这是否更有意义? – LukeTerzich 2015-02-10 00:43:17
你也可以显示'touchesBegan'代码吗? – rakeshbs 2015-02-10 00:45:45