I am trying to get an SKScene presentScene with transition behavior to work. The presentScene technically works although all I get is the default MoveUp transition behavior. I am loading a SpriteKit Scene from archive for the scene. It doesn't seem to matter what I put in for the transition type, I always get the default behavior. I have debugged to make sure that the transition has a value (i.e., not nil). I am using iCloud and coreData managed objects, although I don't know how this would impact the scene presentation. I have included the managed object code in the viewWillAppear.
class GameViewController: UIViewController, GameDelegate {
var managedObjectContext: NSManagedObjectContext!
var heroCharacter : HeroCharacter!
override func viewDidLoad() {
super.viewDidLoad()
presentGameScene()
}
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
// access the application managed object context - jwg
managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
// Persistant Store Changes uses the coordinator
NSNotificationCenter.defaultCenter().addObserver(self, selector: "receivePersistantStoreDidChange", name: NSPersistentStoreCoordinatorStoresDidChangeNotification, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "receivePersistantStoreWillChange:", name: NSPersistentStoreCoordinatorStoresWillChangeNotification, object: managedObjectContext.persistentStoreCoordinator)
// iCloud notifications using the coordinator
NSNotificationCenter.defaultCenter().addObserver(self, selector: "receiveICloudChanges:", name: NSPersistentStoreDidImportUbiquitousContentChangesNotification, object: managedObjectContext.persistentStoreCoordinator)
}
// MARK: scenes
func presentGameScene() {
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as! SKView
skView.showsFPS = true
skView.showsNodeCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
scene.scaleMode = .AspectFill
// set target values
scene.heroCharacter = heroCharacter
scene.viewDelegate = self
// this transition is not working
let transition = SKTransition.fadeWithDuration(10)
skView.presentScene(scene, transition: transition)
}
}
The scene code is pretty generic as well
override func didMoveToView(view: SKView) {
// access the application managed object context - jwg
managedObjectContext = (UIApplication.sharedApplication().delegate as! AppDelegate).managedObjectContext
// Setup physics world's contact delegate
physicsWorld.contactDelegate = self
// Setup waterfall
waterfall = self.childNodeWithName(kWaterfallName) as? SKSpriteNode
// Setup goal
goal = self.childNodeWithName("goal") as? SKSpriteNode
// Setup initial camera position
updateCamera()
// load texture atlases
CharacterSprite.loadTextureAtlasArrays()
var textureAtlasArray = [SKTextureAtlas]()
textureAtlasArray.append(SKTextureAtlas(named: kIcebergAtlas))
SKTextureAtlas.preloadTextureAtlases(textureAtlasArray, withCompletionHandler: { () -> Void in
#if DEBUG
print("completed loading atlases")
#endif
self.startScene()
})
}
func updateCamera() {
if let camera = camera {
camera.position = CGPoint(x: characterSprite!.position.x, y: characterSprite!.position.y)
}
}