gpt4 book ai didi

ios - 真实设备上的 Core Graphics 游戏性能

转载 作者:行者123 更新时间:2023-11-29 02:09:32 25 4
gpt4 key购买 nike

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

最佳答案

这似乎是一种糟糕的做事方式,您真的应该研究更合适的框架,例如 SpriteKit .

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

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

关于ios - 真实设备上的 Core Graphics 游戏性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29429990/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com