我在Xcode 6 iOS模拟器上发现了一个奇怪的行为。
即使我的GameScene中只显示一个菜单,模拟器FPS区域也非常低,大约为20 FPS。
是否存在可能导致此问题的已知问题? 此外,当我开始自己的游戏时,它会立即从大约30FPS降至19 FPS。
这是我在启动时加载的代码:
override func didMoveToView(view: SKView) {
var sud:NSUserDefaults = NSUserDefaults.standardUserDefaults()
if(sud.valueForKey("highscores") != nil){
highScores = sud.valueForKey("highscores") as [Int]
}else{
highScores = [0, 0]
sud.setValue(highScores, forKey: "highscores")
}
createColors()
createStartMenu()
}
func createColors(){
colorArray = [
ColorClass(name: "greenSea", color: greenSea),
ColorClass(name: "emerald", color: emerald),
ColorClass(name: "peterRiver", color:peterRiver),
ColorClass(name: "amethyst", color:amethyst),
ColorClass(name: "wetAsphalt", color:wetAsphalt),
ColorClass(name: "sunFlower", color:sunFlower),
ColorClass(name: "carrot", color:carrot),
ColorClass(name: "pumpkin", color:pumpkin),
ColorClass(name: "alizarin", color:alizarin),
ColorClass(name: "pomeGranate", color:pomeGranate),
ColorClass(name: "clouds", color:clouds),
ColorClass(name: "asbestos", color:asbestos)]
}
func setSceneBackground(){
var background = SKSpriteNode(color: myBackgroundcolor, size: CGSizeMake(self.frame.width, self.frame.height))
background.position = CGPointMake(self.frame.width/2, self.frame.height/2)
self.addChild(background)
}
func createStartMenu(){
self.removeAllChildren()
setSceneBackground()
reset()
var background = SKSpriteNode(color: myBackgroundcolor, size: CGSizeMake(self.frame.width/1.2, self.frame.height/1.5))
background.position = CGPointMake(self.frame.width/2, self.frame.height/2)
var buttonSize:CGSize = CGSizeMake(background.size.width - 20, background.size.height/4 - 15)
background.setScale(0)
var alizarin = UIColor(rgba: "#e74c3c")
playLevelsButton = SKSpriteNode(color: alizarin, size: buttonSize)
playLevelsButton.position.y = buttonSize.height + buttonSize.height/2 + 15
var fontSize = buttonSize.height/2
playLevelLabel = SKLabelNode()
playLevelLabel.fontSize = fontSize
playLevelLabel.text = "Easy"
playLevelLabel.name = "playLevelLabel"
playLevelLabel.fontName = myFont
playLevelLabel.zPosition = 1
playLevelLabel.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
playLevelsButton.addChild(playLevelLabel)
var carrot = UIColor(rgba: "#e67e22")
playMoreDifficultButton = SKSpriteNode(color: carrot, size: buttonSize)
playMoreDifficultButton.position.y = buttonSize.height/2 + 5
playMoreDifficultLabel = SKLabelNode()
playMoreDifficultLabel.text = "Difficult"
playMoreDifficultLabel.fontName = myFont
playMoreDifficultLabel.fontSize = fontSize
playMoreDifficultLabel.name = "playMoreDifficultLabel"
playMoreDifficultLabel.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
playMoreDifficultButton.addChild(playMoreDifficultLabel)
var sunFlower = UIColor(rgba: "#f1c40f")
howToPlayButton = SKSpriteNode(color: sunFlower, size: buttonSize)
howToPlayButton.position.y = -buttonSize.height/2 - 5
howToPlayLabel = SKLabelNode()
howToPlayLabel.text = "How To Play"
howToPlayLabel.fontSize = fontSize
howToPlayLabel.fontName = myFont
howToPlayLabel.name = "howToPlayLabel"
howToPlayLabel.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
howToPlayButton.addChild(howToPlayLabel)
var emerald = UIColor(rgba: "#2ecc71")
highScoreButton = SKSpriteNode(color: emerald, size: buttonSize)
highScoreButton.position.y = -buttonSize.height - buttonSize.height/2 - 15
highScoreLabel = SKLabelNode()
highScoreLabel.text = "Highscore"
highScoreLabel.fontSize = fontSize
highScoreLabel.fontName = myFont
highScoreLabel.name = "highScoreLabel"
highScoreLabel.verticalAlignmentMode = SKLabelVerticalAlignmentMode.Center
highScoreButton.addChild(highScoreLabel)
//Names
playLevelsButton.name = "playLevels"
playMoreDifficultButton.name = "playMoreDifficult"
howToPlayButton.name = "howToPlay"
highScoreButton.name = "highScore"
background.addChild(playLevelsButton)
background.addChild(playMoreDifficultButton)
background.addChild(howToPlayButton)
background.addChild(highScoreButton)
self.addChild(background)
background.runAction(SKAction.scaleTo(1, duration: 0.3))
}
func reset(){
correctColors = []
tileArray = []
tempArray = []
amountCorrect = 0
tapped = 0
gameStarted = false
maxTime = nil
timeStamp = 0
tileFrameSize = nil
searchColor = nil
tileColors = []
}
答案 0 :(得分:8)
SpriteKit使用OpenGL ES在设备上进行GPU加速渲染。在iOS模拟器中,OpenGL ES支持由软件渲染器提供。因此,OpenGL ES的任何使用 - 无论是单独使用还是通过SpriteKit或SceneKit - 在模拟器上与在实际设备上具有非常不同的性能特征。
永远不要依赖iOS模拟器来进行性能测量,尤其是涉及任何GPU相关时。
答案 1 :(得分:1)
Sprite Kit Simulator存在一个已知问题......它具有误导性。我的游戏在设备上运行60FPS,在模拟器中运行最大30FPS。
人们会在设备上玩游戏,而不是在模拟器中进行测试,因此需要进行测试。