Reputation: 11
What is wrong with my code here? I am trying to transition from GameScene to ActionScene. In the simulator there is no response to the touch on sprite. Please Help!!
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* Setup your scene here */
let sprite = SKSpriteNode(imageNamed:"Spaceship")
sprite.xScale = 0.5
sprite.yScale = 0.5
sprite.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame))
self.addChild(sprite)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
for touch in touches {
let location = touch.locationInNode(self)
let touchedNode = nodeAtPoint(location)
if touchedNode.name == "sprite" {
let transition = SKTransition.revealWithDirection(.Down, duration: 0.5)
let ActionScene = GameScene(size:scene!.size)
ActionScene.scaleMode = .AspectFill
scene?.view?.presentScene(ActionScene, transition: transition)
}
}
}
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
Upvotes: 0
Views: 116
Reputation: 544
You initialised your ActionScene
wrong. If you want to transition to ActionScene, you cannot initialise GameScene (because I am assuming you are already on GameScene and are trying to transition to actionScene). So change this code
let actionScene = GameScene(size:scene!.size)
to this
let actionScene = ActionScene(size:scene!.size)
Upvotes: 1