I have this piece of code:
self.view!.presentScene(Level1(size: self.size), transition: transition)
It's called from a menu, when I click a button, it works fine but there seems to be some kind of lag.
I click the button and after a couple of seconds I see the transition and then the next view loads.
Is this normal - what causes the lag?
So after Whirlwinds comment about sound files , I removed them all, no apparent change.
I looked at the screen with CPU , Memory etc.. when I try and load the scene CPU usage shoots up to 99% , then drops down to 80% when the scene has loaded.
Memory is around 44%.
So maybe that does suggest I should preload the images?
Would do this on the menu scene - after the first white screen, from the users point of view they wouldn't notice a couple of extra seconds of loading?
Update: 25th April
Im now preloading textures like this:
SKTextureAtlas.preloadTextureAtlases([
tilesAtlas,
PlayerShootAtlas,
PlayerForwardsAtlas,
PlayerBackwardsAtlas,
PlayerIdleAtlas,
PlayerJumpAtlas
], withCompletionHandler: { () -> Void in
print("----> Before loaded ...")
self.loadMenu()
print("----> After loaded ...")
})
The menu scene is pretty quick to load, the only difference between the menu scene and the level1 scene is the amount of nodes that level one has, the menu scene and level 1 scene are sub classes of a game scene class.
Will try the fonts next,
Maybe its the way I'm loading the nodes?
import SpriteKit
class EncounterManager
{
var encounterNames:[String] = []
var currentEncounterIndex:Int = 0
var previousEncounterIndex:Int = 0
var encounters:[SKNode] = []
var levelYpos:CGFloat = 60.0;
func createNodes( encounterNames:[String])
{
self.encounterNames = encounterNames
for encounterFileName in encounterNames
{
let encounter = SKNode()
if let encounterScene = SKScene(fileNamed: encounterFileName) {
for placeholder in encounterScene.children {
let node = placeholder as SKNode
switch node.name! {
// entities
case "Level-end":
let end = LevelEnd()
end.spawn(encounter, position:node.position, size:CGSize(width: 72, height: 33), useLeft:false);
break
case "Platform-left":
let platform = Platform()
platform.spawn(encounter, position:node.position, size:CGSize(width: 72, height: 33), useLeft:true);
break
case "Platform-right":
let platform = Platform()
platform.spawn(encounter, position:node.position, size:CGSize(width: 72, height: 33), useLeft:false);
break
case "Bat":
let bat = Bat()
bat.spawn(encounter, position: node.position)
break
case "Bee":
let bee = Bee()
bee.spawn(encounter, position: node.position)
break
It needs to be refactored the switch statement is pretty long.
Also Im getting, 60FPS with around 40 to 80 nodes - I don't use the simulator, only an iPhone 5