【问题标题】:Core Graphics Games performances on Real Devices真实设备上的核心图形游戏性能
【发布时间】:2015-04-03 10:00:14
【问题描述】:

我使用 swift 和 UIKit 为简单的游戏创建图形,使用间隔 = 0.03。大约是 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。那么,如何在真机上获得更好的性能。 我只画了一个图像,所以我想画更多性能最好的图像。有什么帮助吗?

【问题讨论】:

    标签: ios performance swift uikit core-graphics


    【解决方案1】:

    这似乎是一种可怕的做事方式,您真的应该寻找更合适的框架,例如SpriteKit

    我自己不是游戏开发者,但使用 NSTimer 似乎是个坏主意,尤其是在性能很重要的情况下。简而言之,您应该重新考虑重绘屏幕的时间和方式的逻辑,而不是每 x ms 强制重绘一次,而是让系统为您决定这一点,例如,如果您使用 CoreAnimation 制作动画,系统将是只重绘部分屏幕等。

    简而言之,阅读游戏引擎并可能重新考虑您的方法,祝您好运!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-16
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      • 2020-12-11
      • 1970-01-01
      相关资源
      最近更新 更多