views:

4787

answers:

2

Hi, i am trying to build an iphone app by using cocos2d. but i have used four types of classes like bellow-

@interface MenuScene : Scene {}

@end
@interface FlipView : UIImageView
{
    CGPoint startTouchPosition;
    NSString *dirString;
    UIImageView *firstPieceView;   
    UIImageView *secondPieceView;

}
@end

@interface HelloController : UIViewController
@end


@interface MenuLayer: Layer{
     Todo *todo;
     Menu * menu;
     sqlite3 *database;
     NSMutableArray *todos;
    NSString *dirString;
    CGPoint startTouchPosition;
}
@property (nonatomic, retain) NSMutableArray *todos;
-(void) button1: (id)sender;
-(void) button2: (id)sender;
-(void) black_jack: (id)sender;
@end

but how can i show FlipView and HelloController classe through MenuLayer class.

+1  A: 

It's very difficult to answer this question just from the code but I think you need to go back and read up a little on UIKit design and cocos2d programming.

HelloController is a view controller - you cannot 'show' it. A view controller is a class that replies to messages from a view and controls the data it displays from the model.

FlipView is an ImageView which is a subclas of UIView. To have UIKit render this image, you need to add it to another view using [UIView addSubView:...]

Here's what I think you want to do:

  1. The menu item receives a touch event. It signals to:
  2. the view controller which
  3. adds the UIImage to the main view

Like I said though, this is a very general question and I really think you should go back to the documentation and think about your design. The Apple docs are good and there are some good iPhone books on the market now.

Roger Nolan
+9  A: 

If you are asking how to attach UIKit views and such to a cocos2d-iphone project, you just have to do it like:

[[[Director sharedDirector] window] addSubview:myView];

Updated to cocos 0.7 and now this is:

[[[Director sharedDirector] openGLView] addSubview:myView];
Genericrich
What shouldI do to remove myView. When I press a button in present scene I move to next scene. But, the added myView is still appearing in that scene too.Thank You.
srikanth rongali
Sorry I did not check well before asking. I got it. I added the following code in the selector for the button. for (id sv in subviews) { [((UIView *)sv) removeFromSuperview]; [sv release]; }
srikanth rongali