This is the first time i have this problem .
-(void)onEnter
{
[super onEnter];
winSize = [[CCDirector sharedDirector] winSize];
NSLog(#"wins:%f",winSize.height);
is returning 480 on iPhone5 simulator .
Whats wrong here ?? its in onEnter ..
Add Default-568h#2x.png (640x1136) to your Xcode target.
Already added then checkout my answer here:
[[CCDirector sharedDirector]winSize] is wrong
Related
I am using Tabbar view controller as parent view controller. I am adding it from interface builder as shown in the below screen shot. Everything is working fine but the viewdidload,viewwillappear and viewdidappear methods are not calling from the begining. even if the viewcontroller is loading for the first time also. can any one please help me out code in my app delegate is
ScreenShot of IB: http://i58.tinypic.com/u4o6w.png
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.backgroundColor = [UIColor whiteColor];
self.tabBarController.tabBar.barTintColor = [UIColor blackColor];
self.window.rootViewController = self.tabBarController;
//[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
return YES;
}
I am able to see the loaded views but the methods are not calling.
Can any one please help me out
i have a UIKit menu based on UIButtons, when i click on one of them i'm firing a cocos2D scene. i'm setting up the CCDirector in the AppDelegate :
if( ! [CCDirector setDirectorType:kCCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:kCCDirectorTypeDefault];
CCDirector *director = [CCDirector sharedDirector];
[director setAnimationInterval:1.0/60];
[director setDisplayFPS:YES];
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
and in the rootViewController (the viewController that will holds my EAGLView) i'm doing this in the viewDidLoad method :
glView = [EAGLView viewWithFrame:self.view.bounds
pixelFormat:kEAGLColorFormatRGBA8
depthFormat:0
];
glView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:glView atIndex:0];
[[CCDirector sharedDirector] setOpenGLView:glView];
CCScene *scene = [GameScene sceneWithParent:self];
[[CCDirector sharedDirector] runWithScene:scene];
i'm setting up my menu in the MainMenuViewController, from where i push the RootViewController in the stack of a navigationController. This works perfectly and my game starts without problems. I can also go back with a UIButton from the RootViewController (which holds the cocos2d scene) : - (IBAction)goBack {
[self.navigationController popViewControllerAnimated:YES];
[[CCDirector sharedDirector] end];}
but when i try to reload my game scene the application quit. i've tried this method :
restart CCDirector but in vain!! i've tried to pause the CCDirector and restart animation but also in vain, the error that i'm getting is in relation with the draw method of cocos2d!!
please help
i've just solved my problem. so if you are trying to use a UINavigationController you don't have to use [[CCDirector sharedDirector] end], because when the rootController is poped from the stack, all the scenes of cocos2d world will be released. But if you are trying to removing only the subview (not the hole controller) you have to end the CCDirector!! my problem was in a singleton class that i added as a child of GameScene, when i ended the CCDirector it still exists in the memory so i had to release it before recreating the game scene..hope this was clear.
how to create menu on any other View it mean's i m created a UIView and i want to add MenuButton on it. This is my code but it is not working properly.. The UIView is hides the MuneButton..
UIView *aview;
aview = [[UIView alloc]initWithFrame:CGRectMake(50, 50, 300,250)];
aview.backgroundColor= [UIColor redColor];
[[[CCDirector sharedDirector] openGLView] addSubview:aview];
// Standard method to create a button
CCMenuItem *menuItem1 = [CCMenuItemImage
itemFromNormalImage:#"Icon.png" selectedImage:#"Icon.png"
target:self selector:#selector(NextButton:)];
menuItem1.position = ccp(100, 60);
CCMenu *starMenu = [CCMenu menuWithItems:menuItem1, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
and
(void) NextButton: (CCMenuItem *) menuItem
{
NSLog(#"Button1");
}
how to add Menu on UIView. I Try with AddSubview removing addChild. And i try aview removing self..
Hope it help to you..
http://www.cocos2d-iphone.org/wiki/doku.php/prog_guide:index
When you add a subview to a UIView, you are essentially adding them on top of the view. The cocos layer is always at the bottom. You can add the view to the root view controller, but you'll take a performance hit.
You're going about this in the wrong way anyway. Put your button in a CCLayer subclass with a CCColorLayer background and add that to your running scene. In your case: self.
My Learn Cocos2D book (2nd Edition) has a chapter about UIKit integration that explains how you can place UIKit views in front of and behind the Cocos2D GL view while allowing all views (front views, cocos2d view, back views) to respond to touch events.
i have menu with buttons
when touch the Play button
game go to another scene
but Touch don't work there
i'm write
self.isToucheEnabled=YES;
in init method
and add in onEnter method
[[CCTouchDispatcher sharedDispatcher] setDispatchEvents:YES];
but that don't work
pleas help why i can enable touch
You must put the following code:
-(void) onEnter {
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:0 swallowsTouches:YES];
}
inside the scene you want to enable the TouchDispatcher on, then in the same scene make sure you enter this:
-(void) onExit {
[[CCTouchDispatcher sharedDispatcher] removeDelegate: self];
}
and the touch should register in every scene that you have the above code in.
This is an example of how you define a menu in cocos2d (source):
CCMenuItem *starMenuItem = [CCMenuItemImage temFromNormalImage:#"ButtonStar.jpg" selectedImage:#"ButtonStarSel.jpg" target:self selector:#selector(starButtonTapped:)];
starMenuItem.position = ccp(60, 60);
CCMenu *starMenu = [CCMenu menuWithItems:starMenuItem, nil];
starMenu.position = CGPointZero;
[self addChild:starMenu];
If you need more help, please provide the code that you are using to create the menu.
You also have to add UIGestureRecognizerDelegate interface in your CCLayer in your header!
e.g.:
#interface YourScene : CCLayer <UIGestureRecognizerDelegate> {
}
In the layer use:
-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
Not:
-(BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
I want to know how to show modal view in cocos2d? Any one can help me?
Thanks before. Regards. :)
I use this code for presenting a GKLeaderboard within cocos2d.
GKLeaderboardViewController *leaderboardController = [[GKLeaderboardViewController alloc] init];
UIViewController *container = [[UIViewController alloc] init];
[container setView:[[CCDirector sharedDirector] openGLView]];
[container setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
leaderboardController.leaderboardDelegate = container;
[container presentModalViewController: leaderboardController animated: YES];
This will do what you want. Don't forget you need to release the UI objects when your done with them.