0

As I've been coding a game in sprite kit, I've noticed that adding even 1 image severely drops framerate from 60 to 30, is there any reason why this is happening? Am I doing the code inefficiently? It's very simple.

This code runs at 30 FPS

import SpriteKit

class OptionMenu: SKScene
{
var Screen: SKSpriteNode!

override func didMoveToView(view: SKView)
{
    Screen = SKSpriteNode()
    self.addChild(Screen)
    addBg()

}

func addBg(){
    let MainMenu = SKSpriteNode(imageNamed: "MainMenu")
    MainMenu.position = CGPointMake(frame.width / 2, frame.height / 2)
    addChild(MainMenu)

}    
}

This code runs at 60 FPS

import SpriteKit

class OptionMenu: SKScene
{
var Screen: SKSpriteNode!

override func didMoveToView(view: SKView)
{
    Screen = SKSpriteNode()
    self.addChild(Screen)
}
}

I don't understand how just one image can affect framerate this severely? BTW the image is like 1000 by 700 ish pixels Thanks, Brennan

Edit: Also I should add the code in the GameViewController()

override func viewDidLoad() {
    super.viewDidLoad()
    let scene = OptionMenu()
    // 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
    scene.size = skView.bounds.size
    skView.presentScene(scene)

}

Edit 2: A similar thread already exists: iOS Simulator games run very slow (low fps)

My question here is slightly different in that I am wondering if I am capping my framerate unintentionally. When I add an image the FPS stays constant at 30.0 FPS, which would signify to me its not lag due to the poor simulator, but that I am capping it somehow.

Community
  • 1
  • 1
Brennan Adler
  • 895
  • 2
  • 8
  • 18
  • Are you running this on the simulator? – ABakerSmith Apr 29 '15 at 14:10
  • Yes, is this an Xcode bug or some setting on the simulator within Xcode? – Brennan Adler Apr 29 '15 at 15:31
  • 1
    Have a look at this: http://stackoverflow.com/questions/19556867/ios-simulator-games-run-very-slow-low-fps – ABakerSmith Apr 29 '15 at 15:52
  • Alright, makes somewhat sense. The only thing is my program isn't lagging at all. Adding an image seems to add a cap to the frame rate at 30. Do you get what I'm saying? – Brennan Adler Apr 29 '15 at 17:20
  • I see what you mean. Have you got a device to test your app on? That way you'll know if it's just the simulator or if there's something else going on. – ABakerSmith Apr 29 '15 at 17:52
  • Yah, I think you need to pay the apple developer fee for that and I'm holding off on that until I think the game is functional, I was hoping there would be a way to tell without that but I guess I can just wait until I think its done to see if there is a legitimate issue. – Brennan Adler Apr 29 '15 at 18:10
  • 1
    The iOS simulator has a ridiculously low frame rate when running Sprite Kit games. My game runs less than 5 fps on simulator and 60 fps on a real iPhone 4S. – Epic Byte Apr 30 '15 at 01:36
  • 1
    The simulator actually runs GPU calls on a CPU like ordeal. Basically, it emulates GPU calls and it's super super slow. If you ever use OpenGL in the simulator, you'll see these hits immediately. Don't trust the FPS the sim gives you. Always test on a device when it comes to GPU bound stuff. – TheCodingArt Apr 30 '15 at 02:11

1 Answers1

0

Yes, it is normal especially on iOS Simulator. If the MainMenu image covers almost completely the screen, only a single image is enough to see fps drops from 60 to 30. iOs symulator emulates OpenGL ES via a software renderer!

Try running your test code on a real iPhone and you'll see the fps up again.

M.Moro
  • 852
  • 9
  • 8