Cocos2D CCScene black screen, nothing happens?

I have been trying to update the last 3 days from Cocos2D 1.1.0-pre-> 2.0rc0a , but this is the hardest task I have ever faced while building my application. So in Cocos2D 1.1 everything was fine, my images loaded, everything worked, etc. Now in 2.0rc0a it just goes to black screen YET, all my methods are called!

Here's some information about the code I'm using, devices, logs, etc.

Xcode version

1. Xcode version: 4.3.2

      

Devices tested on

2. A) Devices: iPhone 4S - 5.0.1 (doesn't work)
B) iPad 3 - 5.1 (doesn't work)
C) iPhone 5.1 simulator (doesn't work)
D) iPad 5.1 simulator (doesn't work)

      

My code

I have a UIViewController class that contains a CCGLView. Then I have the CCLayer class, which has everything for a real game. The code in the CCLayer class is fine because it works in Cocos2D 1.1.0-pre, so I'll post the code for the UIViewController class:

- (void)viewDidLoad {
    [super viewDidLoad];

    // Create an CCGLView with a RGB565 color buffer, and a depth buffer of 0-bits
    CCGLView *glView = [CCGLView viewWithFrame:[self.view bounds]
                                   pixelFormat:kEAGLColorFormatRGB565   //kEAGLColorFormatRGBA8
                                   depthFormat:0    //GL_DEPTH_COMPONENT24_OES
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];
    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
    director_.wantsFullScreenLayout = YES;
    [director_ setDisplayStats:YES];
    [director_ setAnimationInterval:1.0/60];
    [director_ setView:glView];
    [director_ setDelegate:self];
    [director_ setProjection:kCCDirectorProjection2D];
    [director_ setDepthTest:FALSE];
    if(![director_ enableRetinaDisplay:YES])
        CCLOG(@"Retina Display Not supported");
    [CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
    [CCFileUtils setiPhoneRetinaDisplaySuffix:@"@2x"];
    [CCFileUtils setiPadSuffix:@"-72"];
    [CCFileUtils setiPadRetinaDisplaySuffix:@"@2x~ipad"];
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];
    [director_ pushScene:[CCSceneGame scene]];
}

      

Then I have this basic CCScene method in my CCLayer class:

+(CCScene *) scene
{
    CCScene *scene = [CCScene node];
    CCSceneGame *layer = [CCSceneGame node];
    [scene addChild:layer];
    return scene;
}

      

Most of this code is copied directly from template projects. Also I have delegates declared in .h's.

Console output

This is the console from my testing on my 5.0.1 iPhone 4S:

2012-03-31 17:14:54.484 App[56089:707] cocos2d: OS version: 5.0.1 (0x05000100)
2012-03-31 17:14:54.485 App[56089:707] cocos2d: GL_VENDOR:   Imagination Technologies
2012-03-31 17:14:54.486 App[56089:707] cocos2d: GL_RENDERER: PowerVR SGX 543
2012-03-31 17:14:54.486 App[56089:707] cocos2d: GL_VERSION:  OpenGL ES 2.0 IMGSGX543-63.14.2
2012-03-31 17:14:54.488 App[56089:707] cocos2d: GL_MAX_TEXTURE_SIZE: 4096
2012-03-31 17:14:54.488 App[56089:707] cocos2d: GL_MAX_TEXTURE_UNITS: 8
2012-03-31 17:14:54.489 App[56089:707] cocos2d: GL_MAX_SAMPLES: 4
2012-03-31 17:14:54.489 App[56089:707] cocos2d: GL supports PVRTC: YES
2012-03-31 17:14:54.490 App[56089:707] cocos2d: GL supports BGRA8888 textures: YES
2012-03-31 17:14:54.490 App[56089:707] cocos2d: GL supports NPOT textures: YES
2012-03-31 17:14:54.491 App[56089:707] cocos2d: GL supports discard_framebuffer: YES
2012-03-31 17:14:54.491 App[56089:707] cocos2d: compiled with Profiling Support: NO
2012-03-31 17:14:54.492 App[56089:707] cocos2d: cocos2d v2.0.0-rc0
2012-03-31 17:14:54.493 App[56089:707] cocos2d: Using Director Type:CCDirectorDisplayLink
2012-03-31 17:14:54.745 App[56089:707] cocos2d: CCTexture2D: Using RGBA888 texture since image has no alpha
2012-03-31 17:14:54.891 App[56089:707] cocos2d: CCTexture2D. Can't create Texture. cgImage is nil
2012-03-31 17:14:54.892 App[56089:707] cocos2d: Couldn't add image:particleTexture.png in CCTextureCache
2012-03-31 17:14:54.999 App[56089:707] cocos2d: animation started with frame interval: 60.00

      

Several other points

  • My app is all UIKit except for this view
  • I am showing a UIViewController where CCGLView does [self addSubview:]; if it matters
  • I have successfully imported Cocos2D to the point where I have no red files, no warnings, no errors, no deprecated APIs, etc.
  • My images have been modified so I have suffixes that I changed CCFileUtils to code. So this: @ 2x, -72 and @ 2x ~ ipad
  • I also checked the interface builder for some strange events and there are none

If anyone knows what's going on, let me know !!!

Thank!

+3


source to share


2 answers


All @ LearnCocos2D was true though. The true solution for me was to declare the IBOutlet CCGLView in .h and connect it via the Interface Builder.

I think there might be a problem if you are using old projects and then switch to Cocos2D for some odd reason.



So instead of doing it programmatically, just do it with Interface Builder.

+1


source


I repeat myself, but alas:

If you need to update cocos2d on an existing project, the most important thing is to remove all cocos2d files from the Xcode and Finder project. Then move the new version of cocos2d into place and add it again.

Otherwise, you may have old cocos2d files in your project or missing new added files.



If the screen remains black, it may indicate a shader problem. The new version of cocos2d has all shaders as strings in header files (.h). If you haven't added them, they won't work. Not sure if this will give you black screen or crashes.

Finally, since Cocos2D 2.0 uses OpenGL ES 2.0, you will have to rewrite any custom OpenGL drawing code that you have in your project.

Other things you should check is that glView is non-zero and maybe set a breakpoint in CCDirector's update method (visit / draw) to check if it is actually visiting all nodes and drawing them correctly.

+2


source







All Articles