I was working on a game in Cocos2D 1.0 (based on the tutorials in Learning Cocos2D) and just upgraded to Cocos2D 2.0, following the official directions here, making sure to delete the old cocos2d library and replace it completely with the new one.
The code produces no errors, but after showing the Cocos2D startup image, it gives me a black screen with a garbled image where the frame rate counter used to be.
Screenshot (image saves as portrait, even though the simulator is in landscape)
I'm not quite sure where to look for the problem (this is my first Cocos2D project), so I'll start with some code from my AppDelegate.m and some corresponding debugger output.
Code:
-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Init the window
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
CCDirector *director = [CCDirector sharedDirector];
// Init the View Controller
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES;
//
// Create the CCGLView manually
// 1. Create a RGB565 format. Alternative: RGBA8
// 2. depth format of 0 bit. Use 16 or 24 bit for 3d effects, like CCPageTurnTransition
//
//
CCGLView *glView = [CCGLView viewWithFrame:[window bounds]
pixelFormat:kEAGLColorFormatRGB565 // kEAGLColorFormatRGBA8
depthFormat:0 // GL_DEPTH_COMPONENT16_OES
];
// attach the openglView to the director
[director setView:glView];
[director setAnimationInterval:1.0/60];
[director setDisplayStats:YES];
// make the OpenGLView a child of the view controller
[viewController setView:glView];
//Required in iOS6, recommended in 4 and 5
[window setRootViewController:viewController];
// make the View Controller a child of the main window, needed for iOS 4 and 5
[window addSubview: viewController.view];
[window makeKeyAndVisible];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
// Removes the startup flicker
//[self removeStartupFlicker];
// Run the intro Scene
[[CCDirector sharedDirector] pushScene: [Level1Scene node]];
return YES;
}
Debugger:
2013-06-14 12:46:01.181 CocosGame[25610:207] cocos2d: cocos2d v2.0.0
2013-06-14 12:46:01.184 CocosGame[25610:207] cocos2d: Using Director Type:CCDirectorDisplayLink
2013-06-14 12:46:06.964 CocosGame[25610:207] cocos2d: OS version: 5.0 (0x05000000)
2013-06-14 12:46:06.965 CocosGame[25610:207] cocos2d: GL_VENDOR: Apple Computer, Inc.
2013-06-14 12:46:06.966 CocosGame[25610:207] cocos2d: GL_RENDERER: Apple Software Renderer
2013-06-14 12:46:06.966 CocosGame[25610:207] cocos2d: GL_VERSION: OpenGL ES 2.0 APPLE
2013-06-14 12:46:06.968 CocosGame[25610:207] cocos2d: GL_MAX_TEXTURE_SIZE: 4096
2013-06-14 12:46:06.968 CocosGame[25610:207] cocos2d: GL_MAX_TEXTURE_UNITS: 8
2013-06-14 12:46:06.969 CocosGame[25610:207] cocos2d: GL_MAX_SAMPLES: 4
2013-06-14 12:46:06.970 CocosGame[25610:207] cocos2d: GL supports PVRTC: YES
2013-06-14 12:46:06.970 CocosGame[25610:207] cocos2d: GL supports BGRA8888 textures: YES
2013-06-14 12:46:06.971 CocosGame[25610:207] cocos2d: GL supports NPOT textures: YES
2013-06-14 12:46:06.972 CocosGame[25610:207] cocos2d: GL supports discard_framebuffer: YES
2013-06-14 12:46:06.972 CocosGame[25610:207] cocos2d: GL supports shareable VAO: NO
2013-06-14 12:46:06.973 CocosGame[25610:207] cocos2d: compiled with Profiling Support: NO
[Switching to process 25610 thread 0x1e0f]
[Switching to process 25610 thread 0x207]
2013-06-14 12:50:38.990 CocosGame[25610:207] cocos2d: surface size: 480x320
Thanks for any help you can offer!
I managed to solve this by replacing my AppDelegate.m, AppDelegate.h, and main.m with new versions from the cocos2d 2.0 templates. I'd built the original project from cocos2d 1.0 templates, and the architecture seems to have changed in ways the migration guide didn't cover in depth.
One Clean and Build, and things were working as they should.
Related
I got one old game and I tied to update Cocos2d 2.0 SDK. I got some compilation error.
b2Vec2 gravity;
gravity.Set(0.0f, -10.0f);
self.world = new b2World(gravity, true);
Error: No matching constructor for initialization of 'b2World'
When I change this to below code then works but Box2D debug shapes are not drawn.
self.world = new b2World(gravity);
How to initialize Box2d world in right way that show debug shapes?
Replace the GLESDebugDraw files with those found in a newly created cocos2d 2.0 + Box2D project. Your version is still using GL ES 1.1 commands which don't work in cocos2d 2.x
Finally I got debug shape by replacing this draw function and GLESDebugDraw files.
-(void) draw
{
[super draw];
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
kmGLPushMatrix();
self.world->DrawDebugData();
kmGLPopMatrix();
}
I am trying to display UIAlert view when my application gets opened from running in the background, but the notification is not getting called until the cocos2d frame interval has dropped from 15 down to 1. I don't understand what this means. Could someone enlighten me. When closing the app it shows this in the debugger.
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15
Then when I reopen the app it shows the same thing.
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 15
but after about 1 or 2 seconds then I get this message `
-[CCDirectorDisplayLink startAnimation] : cocos2d: Frame interval: 1
in the debugger and then it calls the notification?
I was testing my cocos2d-iphone 1.0.1 game on an iPhone 4 with iOS version 4.3.3. It is a landscape mode game.
I recently updated Xcode to 4.5.2, and it comes with iOS simulator 6.0.
If I run my game on the simulator (Hardware set to retina iPhone 4), the device window rotates to the expected position, but the game itself seems to be rotated 90 degrees to the right. The touches also seem to be caught rotated. So basically, I have the device window in the correct orientation but the game itself is rotated.
When I run this on the iPhone 4, it all works just fine.
What could have happened?
This solved it: Cocos2D with iOS6 faulty rotation
Just had to use the Cocos2d 1.1 link, which is: https://github.com/cocos2d/cocos2d-iphone/blob/develop/templates/Xcode4_templates/cocos2d.xctemplate/AppDelegate.m
Based on the use CCDirector makes of CCLabelAtlas, I tried the following:
scoreLabel = [[CCLabelAtlas alloc] initWithString:#"0123456789" charMapFile:#"fps_images.png" itemWidth:8 itemHeight:12 startCharMap:'.'];
[scoreLabel setPosition:ccp(200, 200)];
[self addChild:scoreLabel];
I must be missing something as nothing displays. I'm using the basic .png that's supplied with Cocos2D.
What am I missing? Thanks!
The app keeps crashing, and I'm not able to make any sense out of the debugging messages. I'm sorry if this isn't enough information, but the smallest hint will be a big help to me! :D
2011-08-01 17:57:56.827 SpaceViking[1548:207] cocos2d: CCTexture2D. Can't create Texture. UIImage is nil
2011-08-01 17:57:56.827 SpaceViking[1548:207] cocos2d: Couldn't add image:fps_images.png in CCTextureCache
2011-08-01 17:57:56.828 SpaceViking[1548:207] cocos2d: Could not open file: fps_images.png
2011-08-01 17:57:56.830 SpaceViking[1548:207] cocos2d: Could not initialize CCAtlasNode. Invalid Texture
2011-08-01 17:57:56.830 SpaceViking[1548:207] Retina Display Not supported
[Switching to process 1548 thread 0x207]
2011-08-01 17:57:56.946 SpaceViking[1548:207] GameObject init
2011-08-01 17:57:56.947 SpaceViking[1548:207] cocos2d: CCSpriteFrameCache: Frame '(null)15.png' not found
2011-08-01 17:57:56.950 SpaceViking[1548:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableArray insertObject:atIndex:]: attempt to insert nil object at 0'
Looks like you are loading an image dynamically that does not exist, the final crash is because NSMutableArray does not allow nil values. Looks like you are appending something to your images for the loading since the image name is '(null)15.png', therefore you need to verify that the prefix you are appending is correct.
(null)15.png
I'm betting you're getting this because you aren't initializing an NSString properly.
NSString *myString;
myString = [NSString stringWithFormat:#"%#%#", myString, #"15.png"];
something like this... your string will default to "nil" until you set it to #""