views:

18

answers:

1

I am going to restructure my game to use multiple uiviews. Is the following flow correct ?

  • I create 6 uiviews ( one for each sprite).
  • game loads root uiview.
  • root uiview init method loads 5 subviews using self addSubview.
  • in the game controller I update each uiview each game tic.
  • the game controller will need a pointer to each Uiview instance.

Thanks all,

Martin

A: 

I would probably use the UIViewController for the main view to load the subviews and add them to the main view, not load the subviews directly in the main UIView itself.

Nimrod
Thanks but I can't get this to work. Do I just use [self.view addSubview : view 2] in my view controller ?
Ohnomycoco
yes, but you'll also need to make sure that subview.frame is set properly. You could also just do all of this in interface builder, create outlets for all the views, connect the outlets, then do all the view moving/animating in the code
Nimrod
Thanks but I'm still stuck. Using view2.frame = CGRectMake(55.0f, 0.0f, 50.0f, 50.0f); [self.view addSubview : view2]; Now gives me a black square on the screen. I'm confused now as to how to get my sprite to draw in this box - I'm using Quartz 2d and a context to draw.
Ohnomycoco
The actual Quartz2D stuff should be done in the drawRect method of a UIView subclass, but instantiating and moving the views around is usually done in the controller. I haven't tried to animate a view that draws itself with drawRect using Core Animation though. I've heard that performance is supposed to be kind of poor that way. Why not just use a UIImageView with a bitmap then rotate and scale it with affine transforms?
Nimrod
Thanks - sounds like what I've got is about right then. I have one UIView which updates 7-8 sprites per game tic in it's drawrect method.
Ohnomycoco