Trying to work views in 3.0

Discussion in 'Public Game Developers Forum' started by Drenguin, Jul 14, 2009.

  1. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    I've been trying to create a simple view-changing app and no matter how many tutorials I watch and no matter how many samples I download I always get the same thing. When I click the button to change the view I get a blank white screen I think this has to do with 3.0 but it's probably just me! Thank you if you can help!
     
  2. PixelthisMike

    PixelthisMike Well-Known Member

    You're saying that the sample programs exhibit the same behaviour?
     
  3. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Yes I used the ones from the schenk studios site and it did the same thing.
     
  4. PixelthisMike

    PixelthisMike Well-Known Member

    Does it run differently on the device compared to in the simulator?
     
  5. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    I can't run it on a device I haven't paid yet.
     
  6. PixelthisMike

    PixelthisMike Well-Known Member

    First thing I would try is reinstalling the SDK, sounds like something is corrupt if you can't run other peoples examples. Assuming here that you haven't modified the example project in any way.
     
  7. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    How do you implement view changes?
     
  8. PixelthisMike

    PixelthisMike Well-Known Member

    Kinda hard to remember because I'm using cocos2d and scene switching now! Basically you should have UIViewController objects that contain UIView objects. When you initialise a view controller you are able to access its view object and add that as a subview of your window or another view if you have some sort of hierarchy going on. That is fairly simplistic though because Interface Builder fits into the equation too if you are using example code.
     
  9. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Okay I'll attempt to change up the code I have and try to get it to work. Is cocao2d very different from obj-c because that's probably alot more powerful for game programming.
     
  10. PixelthisMike

    PixelthisMike Well-Known Member

    cocos2d is mainly obj-c with the odd bit of C/C++ depending on how deep you dig below the surface.
     
  11. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Well that's not too bad I guess I'd better try that. How does the screen switching work?
     
  12. PixelthisMike

    PixelthisMike Well-Known Member

    You use objects called scenes and when you want to switch a scene you go [[Director sharedDirector] replaceScene:newScene], that kind of thing. Then you add sprites, layers etc. as children of the scene.
     
  13. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Cocos is too confusing for me right now I guess I'll wonder if anyone else can help me with my view switching problem?
     
  14. PixelthisMike

    PixelthisMike Well-Known Member

    Cocos actually works in a very similar way to UIKit except you don't have to worry about view controllers and nib files, it's actually more straightforward in my opinion :)

    Can you explain to me how you are going about view switching currently?
     
  15. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Well it turns out I did have to re-install x-code and I setup a view and create a view controller then I input this code in a IBAction

    [self presentModalViewController:playGameController animated:YES];

    As for the confusing thing I get how it works but when I tried I couldn't get animation to work (it said I didn't declare something) and I like being able to draw stuff in interface builder.
     
  16. PixelthisMike

    PixelthisMike Well-Known Member

    Hmmm I prefer to avoid Interface Builder wherever possible except for views that have lots of static subviews. A modal view is normally used for dialog boxes that sit over the top of other views and are usually set to be the only views to receive user input.

    While this should work if you do this for all of your view switching you are going to end up with piles of views all on top of one another and all consuming memory so not the best approach. Trust me you will have enough problems with memory management as it is! ;)

    Let's say that we already have a view loaded, named oldView, and it is the child of another view called parentView. If we want to replace the current view with a new one then we do this:

    Code:
    // create the new view controller from a nib file, this will automatically create a UIView for you
    UIViewController *newViewController = [[UIViewController alloc] initWithNibName:@"newViewNib" bundle:nil];
    // add the newly created view as a subview of parentView
    [parentView addSubview:newViewController.view];
    // remove oldView as a subview of parentView
    [oldView removeFromSuperview];
    // don't forget to release newViewController, unless a reference to it needs to be stored
    [newViewController release];
    I think that about sums it up in simple terms :) As far as animation is concerned it depends what animation you were intending to use?
     
  17. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Well I did something like this
    move = MoveTo(120, 430);
    (the name of my sprite).do move;
    I'm writing on my iPod so that's not exactly what it looked like.
     
  18. PixelthisMike

    PixelthisMike Well-Known Member

    Where did you find this code? This is not something you can do in UIKit. In fact it looks more like how you would do it in cocos2d! Chances are the error you were getting is telling you that MoveTo is undefined.
     
  19. Drenguin

    Drenguin Well-Known Member

    Jan 10, 2009
    87
    0
    0
    Yeah I was talking about cocos2d I did that code and it didn't work in cocos.
     
  20. PixelthisMike

    PixelthisMike Well-Known Member

    Ah right, I thought you had decided against cocos2d and were still using UIKit! In that case, to use MoveTo you do like so:

    Code:
    MoveTo *move  = [MoveTo actionWithDuration:1.0 position:cpv(120, 430)];
    [sprite runAction:move];
    Have you managed to find the cocos2d API reference? Cos you're a fish out of water without it :)
     

Share This Page