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