In Kobold2d certain functions that in Cocos2d is in the appDelegate is in a config.lua file. And this brings me to the problem cause to initialize a Cocos Builder as the first scene in cocos2d you replace this line (in the app delegate)
[director runWithScene: [IntroLayer scene]];
with
[director runWithScene: [CCBReader sceneWithNodeGraphFromFile:#"MainMenuScene.ccbi"]];
but this is all hidden away in Kobold2d - replaced by FirstSceneClassName = "HelloWorldLayer" in the config.lua file.
Anyone knows a bugfree way around this?
You can still use runWithScene, just put it in AppDelegate's initializationComplete method. This will take precedence over loading the scene specified in config.lua.
Related
I have a very simple game using Xcode v4.2.1, Cocos2d v5.0.1. I've tried both compilers in Xcode (LLVM GCC 4.2 and Apple LLVM compiler 3.0. Is there a preference??) On the game screen is a UIKit button that presents the user with a Interface Builder (nib) Settings/Options screen to customize the game a bit. This is all based on what I learned in Ray Wenderlich's tutorial (http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit).
After the user makes their changes, they are returned to the game and the changes are in place.
This all works as I want in the simulator, however, when I test the game on an iPad I get the following errors in the debug window:
2012-01-27 18:25:27.305 BonkBonk[1082:707] failed to call context
2012-01-27 18:25:27.310 BonkBonk[1082:707] cocos2d: surface size: 1024x768
2012-01-27 18:25:27.316 BonkBonk[1082:707] Failed to make complete framebuffer object 8cdd
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]
OpenGL error 0x0506 in -[EAGLView swapBuffers]
The OpeenGl errors continue on indefinitely.
I use the function viewWillAppear to capture the return from the settings/options screen so that I can pass the new settings to the game layer. If I comment out this code the problem goes away, however, I am not able to get the new user settings to the game layer.
Here is the code:
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
//CCScene *scene = [[CCDirector sharedDirector] runningScene];
CCScene *scene = [BonkBonkLayer scene];
id layer = [scene getChildByTag:1];
[layer userSettings];
[super viewWillAppear:animated];
}
The commented out line //CCSene *scene... was another failed attempt at getting the layer object from the scene so that I could call the userSettings method where the game layer then can assimilate it into the game.
OK, so I've found something that alleviates my issue.
If anyone knows anything about this, please let me know. I will continue to use this fix unless I hear a reason from someone more knowledgable than myself (and that's not that difficult).
The solution is found in the comment by "psionic" at the end of the following discussion:
http://www.cocos2d-iphone.org/forum/topic/7068.
Basically, I created a static bool in the EAGLView class (EAGLView.m) that surrounds the call to _resizeFromLayer in the layoutSubViews member function. The call to _resizeFromLayer is only called the first time through, and then never again.
Please read the above discussion and let me know what you like/dislike about this solution, other than the obvious... it's a hack.
A hack,that works. I think.
I had a similar problem. I've integrated cocos2d with UIKit. I added adMob. The problem shows up when user clicks on Ads that presents the google BrowserView. If you dismiss the View using the Done button, the App works fine. However, if user press the Home button when in Browser View, and resume the App, I got the same exception.
OpenGL error 0x0506 in -[EAGLView swapBuffers]
UIKit buttons and the Ads are shown, but it does not render the cocos2d layer.
I got the solution from https://github.com/cocos2d/cocos2d-iphone/pull/198, but I did not change the cocos2d source. Instead, I added a boolean ivar called isAnimating in AppDelegate.m, and expose the property to the Layers.
To solve this, I stop animation on CCDirector before entering google Browser View. and start animation once resume to the App. isAnimating ivar is used to check that start animation is not called twice.
Hope it helps,
I had similar errors in my app when implementing Cocos2D via CCGLView.
The solution that worked for me was to call
[[CCDirector sharedDirector] popScene]
when presenting the Interface Builder Viewcontroller.
I know Cocos2d 2.0 is in alpha and will obviously have certain issues with it. I am trying to convert several projects to use OpenGL 2.0 for multiple reasons, but am having one very strange issue.
When I start up a scene, my textures load as desired and everything works great. I then display some Apple UI elements that allow me to quit the scene. The scene and its view controller are deallocated, the director is told to end, and I return to another view. Then I press a UIButton that launches the scene again. The scene begins again and runs, but no textures are visible. Fonts load and display, audio loads and plays, but no textures are visible. When dumping info from the CCTextureCache, I can see that the desired textures are available in the cache ( [[CCTextureCache sharedTextureCache] dumpCachedTextureInfo] ). I have also tried clearing the cache before the scene is relaunched. No matter what, I can not see any textures or add nodes to the scene.
There could be something wrong with how I reset the scene, or how the EAGLView is setup. Here is the code for starting said scene from a View Controller:
(void)startGame {
CCDirector *director = [CCDirector sharedDirector];
EAGLView *glView = [EAGLView viewWithFrame:[self.view bounds]];
[director setOpenGLView:glView];
[self setView:glView];
[[CCTextureCache sharedTextureCache] removeUnusedTextures];
//[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
[[CCDirector sharedDirector] runWithScene:[Cocos2DChipmunkScene scene]];
}
Then, the scene is quit, and the following is called:
CCDirector *director = [CCDirector sharedDirector];
[[director openGLView] removeFromSuperview];
[director end];
The above startGame method is called again when I try to start the game again. This is the point where no textures are displayed.
Let me know if I need to provide more details on this issue.
My recommendation is to not shut down the director and keep the openGLView in the hierarchy, just set it as hidden: openGLView.hidden = YES;
You can start and stop cocos2d via [[CCDirector sharedDirector] startAnimation] respectively stopAnimation.
I am new to the cocos2d API and have noticed that there are a few ways to set the screens orientation within the templates. I have not been able to figure out the correct way to set my orientation to LandscapeRight and keep it that way throughout the entire game. How do I change my orientation so that it maintains LandscapeRight? Any help is appreciated. Thank you!
The answer here has changed with cocos2d 2.0, as CCDirector is now a ViewController on iOS:
CCDirector no longer supports device orientation. All autorotation and
device orientation is handled by RootViewController now. Fortunately,
[[UIDevice currentDevice] orientation] can be used in place of
[[CCDirector sharedDirector] deviceOrientation]. The enums are the
same, except that they begin with UI instead of CC.
Forcing a specific orientation is a simple matter of returning YES
only to the desired orientation in the RootViewController method
shouldAutorotateToInterfaceOrientation.
Choosing between Cocos2D v1.x & 2.x and Tips for updating to Cocos2D 2.0 at learn-cocos2d.com
Modify GameConfig.h from the cocos2d template.
#define GAME_AUTOROTATION kGameAutorotationNone
/* original code is kGameAutorotationUIViewController. */
And modify AppDelegate.m as well.
#if GAME_AUTOROTATION == kGameAutorotationUIViewController
[director setDeviceOrientation:kCCDeviceOrientationPortrait];
#else
[director setDeviceOrientation:kCCDeviceOrientationLandscapeRight];
/* original code is "Left". */
#endif
Use this line:
[[CCDirector sharedDirector] setDeviceOrientation:kkCCDeviceOrientationLandscapeRight];
In the RootViewController.m,search for the line
return ( UIInterfaceOrientationIsPortrait(interfaceOrientation ));
change it to
return ( UIInterfaceOrientationIsLandscape(interfaceOrientation ));
if you added shouldAutorotateToInterfaceOrientation and not solved your problem
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
THEN
Try to add this line to appDelegate.m
[window_ setRootViewController:navController_];
Good Luck
The correct answer - took me a while to find - is in the info.plist, change the supported interface orientations values, item 0 and item 1 have 4 possible values, Portrait (top home button) etc.
How do I get rid of the numbers in the bottom left of the screen when I am making a cocos2d game? This is probably a newb question, but still.
There is a ShowFPS var in one of the files when you create the initial cocos project. But this should work from anywhere:
[[Director sharedDirector] setDisplayFPS:NO];
if your app delegate.. Look for
[director setDisplayFPS:YES];
change it to
[director setDisplayFPS:NO];
or you can call this anywhere like the previous answer:
[[CCDirector sharedDirector]setDisplayFPS:NO];
Just a heads up for people checking this out at a later date (like me). setDisplayFPS is deprecated now. Use setDisplayStats instead.
[[CCDirector sharedDirector] setDisplayStats:NO];
To show it only when compiling for debug:
#if defined (DEBUG)
[[CCDirector sharedDirector] setDisplayFPS:NO];
#endif
in AppDelegate.cpp file, and the applicationDidFinishLaunching method
// turn on display FPS
pDirector->setDisplayStats(true);
change true to false
for cocos2D 3.0
[[CCDirector sharedDirector] setDisplayStats:YES];
In appdelegate.m
after didfinishlaunchingoptions.
[startUpOptions setObject:#(NO) forKey:CCSetupShowDebugStats];
setObject:#NO (It is YES by default).
I just finished my concept for an iphone app. I have a main program and in that program I want to start a game.
MAIN PROGRAM (BUTTON 1 / BUTTON 2 / START GAME)
|
|
Cocos2d Game
Is this possible? To use cocos2D in a normal "iphone app"???
Thanks so much!!!
It is definitely possible to mix UIKit with Cocos2d. Usually people accomplish this by putting their UIKit views inside a Cocos2d layer. It sounds like you want to embed the Cocos2d game inside a UIKit view instead. This should be possible, but I am unsure of the specifics involved. Try looking at -(BOOL)attachInView:(UIView *) view in CCDirector.
Note that Cocos2d uses OpenGL and there are possible performance issues when mixing OpenGL and UIKit. Pausing Cocos2d when using the other part of your application will help.
I found a vast array of great tutorials on Cocos2D for iPhone at Ray Wenderlich's site. One tutorial you might especially want to check out is
How to integrate Cocos2D and UIKit
Note: the original "Cocos2D" framework was written in Python and not designed for iOS; here's the actual homepage for the iOS port.
It is possible, but you should know that the main core of your app must be controlled by Cocos2D, that means CCDirector needs to be instantiated in AppDelegate.
Start with:
a). install Cocos2D:
Go to Terminal and write (if you save cocos2D file in desktop, if not use the path where you save it)
cd Desktop/cocos2d-iphone-1.1-beta
sudo ./install-templates.sh
and if you couldn't install try again with
./install-templates.sh -f -u
b). Import cocos2d.h inside AppDelegate
c). Declare CCDirector in applicationDidFinishLaunching method inside
AppDelegate (you should check the code for this in Cocos2D template is pretty straight
forward)
I did this in my applicationDidFinishLaunching method:
- (void)applicationDidFinishLaunching:(UIApplication *)application {
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
CCDirector *director = [CCDirector sharedDirector];
// Create an EAGLView with a RGB8 color buffer, and a depth buffer of 24-bits
EAGLView *glView = [EAGLView viewWithFrame:[window frame]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
[glView setMultipleTouchEnabled:YES];
// attach the openglView to the director
[director setOpenGLView:glView];
// Enables High Res mode (Retina Display) on iPhone 4 and maintains low res on all other devices
if( ! [director enableRetinaDisplay:YES] )
CCLOG(#"Retina Display Not supported");
// make the OpenGLView a child of the main window
[window addSubview:glView];
// make main window visible
[window makeKeyAndVisible];
GameScene *gs = [GameScene node];
[[CCDirector sharedDirector] runWithScene:gs];
//General is part of UIKit where I load the tabbar
General *principal;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
principal = [[General alloc] initWithNibName:#"General-iPad" bundle:nil];
} else {
principal = [[General alloc] initWithNibName:#"General" bundle:nil];
}
self.general = principal;
[principal release];
[self showUIViewController:general];
}
To push a scene from tabbar in UIKit
[[CCDirector sharedDirector] pushScene: [CCTransitionMoveInB transitionWithDuration:0.0f scene:[MyScene scene]]];
Next I recommend you to follow Ray Wenderlich's tutorial How to integrate Cocos2D and UIKit and read this post aswell how we can show UIViewController and UIView by using cocos2d? Maybe you should search for some code in the Cocos2D forums too, always help to see that.
EDIT:
1) You can download a easy example from here: UIKit Cocos2D
You could check out this framework too: Kobol2D "is an extended and improved version of the popular Cocos2D for iPhone game engine. Everything you know about Cocos2D can still be applied, and Kobold2D is easier to get started with, more convenient to use, more powerful and flexible than Cocos2D with all the documentation available online and offline. Use Kobold2D to develop iPhone, iPod touch, iPad and Mac OS X games for both Apple App Stores. And it has some examples using UIKIT and Cocos2D".
You can certainly create a game with your requirements in Cocos2D. You might want to ask some follow-up questions over at the Cocos2D forums and read through their documentation.
You can probably do this easily......
You have to only make the (UIView *) view in CCDirector.
after attaching the view.....
Yes.It is very easy and handy to implement Cocos2D with normal Iphone FrameWork.Refer Ray Wenderlich UIKit and Cocos2D Integration Tutorial here.It will helpful to you.
Yes! Is very possible, only install the Cocos2d and his templates.
Inclusive, I used Cocos2d to create simple apps with a lot of effects :)