vendredi 30 janvier 2015

Trying to pass UIImage from one ViewController to my GameScene in spriteKit

I thought it would be interesting to learn how to pass an image from an imagePicker to my GameScene to use as a SKSpriteNode(texture: SKTexture(image: UIImage)) but i keep getting an error after selecting my image and pressing a button to go into my gameScene



override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "startSegue") {

var gameViewController = segue.destinationViewController as GameScene

gameViewController.imageToPass = pickedImage.image

}


anyone know what im doing wrong?


keep getting exc_breakpoint (code=exc_i386_bpt, subcode 0x0) when initializing gameViewController as GameScene


I am trying to pass imageToPass to the GameScene.swift that is created when i create a new game project in Xcode


class GameScene: SKScene {



var imageToPass = UIImage()
var bird = SKSpriteNode()


override func didMoveToView(view: SKView) {
/* Setup your scene here */

var birdTexture = SKTexture(image: imageToPass)
bird = SKSpriteNode(texture: birdTexture)
bird.position = CGPoint(x: CGRectGetMidX(self.frame), y: CGRectGetMidY(self.frame))

self.addChild(bird)
}



Aucun commentaire:

Enregistrer un commentaire