开发者

Performance Gain Using Multiple CALayers in One UIVew

开发者 https://www.devze.com 2023-02-10 00:35 出处:网络
I\'m in the process of writing a simple 2D game which at present does a fair bit of custom drawing for multiple sprites upon each update - i.e. I have game view that delegates to all sprites to perfor

I'm in the process of writing a simple 2D game which at present does a fair bit of custom drawing for multiple sprites upon each update - i.e. I have game view that delegates to all sprites to perform quartz rendering (point/line based) upon each update.

My performance is ok upto around 50 active objects being rendered but now things are starting to slow down so I'm looking to optimize. To do so I've decided to pre-render my sprites to a CALayer then add that to the game view.

My first thought was to give each Sprite instance a CALayer which is added to the GameView's view.layer as sublayer. This would mean that I use a single UIView which has multiple CALayers - one per game sprite.

Would there be a negligible performance loss if I deci开发者_C百科ded to use a UIView for each game sprite?


UIViews are part of the responder chain and will add extra overhead. I started with UIViews for sprites and found gestures became sluggish. I would recommend sticking with CALayers


As far as I know, UIViews are pretty lightweight wrappers around CALayer, so the performance loss shouldn't be too big. But I think a sprite would simply be better represented by an instance of CALayer rather than UIView.

0

精彩评论

暂无评论...
验证码 换一张
取 消