我使用swift和InterKit = 0.03的UIKit为带有Core图形的简单游戏创建Graphics。大约是30FPS
class CView: UIView {
let img = UIImage(named: "background.png")
func initalize(){
var timer = NSTimer.scheduledTimerWithTimeInterval(0.03, target: self, selector: Selector("update"), userInfo: nil, repeats: true)
}
func update(){
setNeedsDisplay();
}
override func drawRect(rect: CGRect){
img?.drawAtPoint(CGPoint(x: 0, y: 0))
}
}
在ViewController的类中,我在所有设备上使用全屏缩放
let mainview = CView()
mainview.initalize()
var rect = UIScreen.mainScreen().bounds
var scaleX = rect.width / 480;
var scaleY = rect.height / 800;
mainview.transform = CGAffineTransformScale(CGAffineTransformIdentity, scaleX, scaleY);
view = mainview
它可以与30FPS的模拟器一起正常工作,但在真实设备(iPhone 4S,Iphone 4),10-14FPS(Iphone 5,5s)上仅为5-8 FPS。因此,如何在真实手机上获得更好的性能。
我只绘制一张图像,所以我想绘制更多具有最佳性能的图像。有什么帮助吗?
最佳答案
这似乎是一种可怕的处理方式,您确实应该研究更合适的框架,例如SpriteKit。
我自己不是游戏开发人员,但是使用NSTimer似乎是个坏主意,尤其是在性能至关重要的情况下。简而言之,您应该重新考虑何时以及如何重画屏幕的逻辑,而不是每隔x ms强制重画一次,而应由系统为您决定,例如,如果您使用CoreAnimation制作动画,则系统将仅重画屏幕的一部分等
简而言之,请仔细阅读游戏引擎并可能重新考虑您的方法,祝您好运!
关于ios - 真实设备上的核心图形游戏性能,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29429990/