I am new to the Swift language and i am following a tutorial that is using a outdated swift language. The tutorial is about creating a animation with png files. So there are 6 png files that in total creates a animation. This is the link of the tutorial "https://www.youtube.com/watch?v=5aCVyrJbrHQ". I have noticed a crucial difference in the old version of Swift and the new one. Here is where i get stuck.
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let shooterNode = self.childNodeWithName("shooterNode")
if(shooterNode != nil) {
let animation = SKAction.animateWithTextures(shooterAnimation, timePerFrame: 0.1)
shooterNode?.runAction(animation)
}
New version: override func touchesBegan(touches: Set, withEvent event: UIEvent?
Old version: override func touchesBegan(touches: NSSet, withEvent event: UIEvent
Error
As soon as i run the simulator and click on the object i get no response, no error just nothing. I checked if i made a typo with the object name but found nothing there.
This is the full code of the entire file in case you would ask for it
import UIKit
import SpriteKit
class ShooterScene: SKScene {
var score = 0
var enemyCount = 10
var shooterAnimation = [SKTexture]()
override func didMoveToView(view: SKView) {
self.initShooterScene()
}
func initShooterScene(){
let shooterAtlas = SKTextureAtlas(named: "shooter")
for index in 1...shooterAtlas.textureNames.count {
let imgName = String(format: "shooter%01d", index)
shooterAnimation += [shooterAtlas.textureNamed(imgName)]
}
}
//Anime the shooter
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let shooterNode = self.childNodeWithName("shooterNode")
if(shooterNode != nil) {
let animation = SKAction.animateWithTextures(shooterAnimation, timePerFrame: 0.1)
shooterNode?.runAction(animation)
}
}
}
GameSwift.scene
import SpriteKit
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
let introLabel = childNodeWithName("introLabel")
if(introLabel != nil) {
let fadeOut = SKAction.fadeOutWithDuration(1.5)
introLabel?.runAction(fadeOut, completion: {
let doors = SKTransition.doorwayWithDuration(1.5)
let shooterScene = SKScene(fileNamed: "ShooterScene")
self.view?.presentScene(shooterScene!, transition: doors)
})
}
}
/* Called before each frame is rendered */
override func update(currentTime: CFTimeInterval) {
}
}
if(shooterNode != nil) {...}
block. – WhirlwindShooterScene
? The actual creation of a new scene (and its transition) should look like thisif let nextScene = ShooterScene(fileNamed: "ShooterScene") {/* present scene here with optional transition*/}
So check that part. – WhirlwindShootingScene
scene (as well as transition) is done inGameScene
's touchesBegan. So, again, where do you present yourShooterScene
? – Whirlwind