ashish
ashish

Reputation:

How we can show UIViewController and UIView by using Cocos2d?

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 class through MenuLayer class.

Upvotes: 7

Views: 14171

Answers (2)

Genericrich
Genericrich

Reputation: 4651

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];

And in Cocos 0.99:

[[[CCDirector sharedDirector] openGLView] addSubview:myView];

And in Cocos 2.0

[[[CCDirector sharedDirector] view] addSubview:myView];

Upvotes: 20

Rog
Rog

Reputation: 17170

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.

Upvotes: 2

Related Questions