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, UIView
s 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
.
精彩评论