IPhone : cannot convert the expression's type '(size: @Ivalue CGSize)' to type 'GameOverScene'

on Wednesday, April 8, 2015

I am a swift beginner. I've been trying to track the highScore in my spriteKit game. but the game wouldn't run when i try to call the GameOverScene from a different Scene, and instead it shows the error above. can anyone please help me go through this. Please see code below


override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {



emphasized text var touch: UITouch = touches.anyObject() as UITouch

var location = touch.locationInNode(self)

var node = self.nodeAtPoint(location)


// If next button is touched, start transition to second scene

var secondScene = GameOverScene(size: self.size)

secondScene.scaleMode = SKSceneScaleMode.AspectFill
self.scene!.view?.presentScene(secondScene)

}


class GameOverScene:SKScene, SKPhysicsContactDelegate {



let gameplayDict : NSDictionary = {
let path = NSBundle.mainBundle().pathForResource("Gameplay", ofType: "plist")
let dict = NSDictionary(contentsOfFile: path!)
return dict!
}()




//Scoring variables
var score : Int = 0 {
didSet {
self.setScore(score)
}
}


var highScore : Int = 0 {
didSet {
self.setHighscore(highScore)
NSUserDefaults.standardUserDefaults().setInteger(highScore, forKey: "highScore")
NSUserDefaults.standardUserDefaults().synchronize()
}
}


required init?(coder aDecoder: NSCoder) {



super.init(coder: aDecoder)

// set value of the highscore to the saved one, if any


if let high = NSUserDefaults.standardUserDefaults().objectForKey("highScore") as?



Int {
highScore = high
}
}

0 comments:

Post a Comment