Cocos 2D - CCSprite使lldb崩溃

时间:2013-05-23 11:46:09

标签: ios objective-c xcode cocos2d-iphone

嗨,我对cocos 2D有点新意。我使用cocos2D v 2.x并从cocos2D模板创建了一个应用程序。 我刚刚在我的场景中添加了5个CCSprite,几分钟后我的fps逐渐降低到10.0以下,app崩溃了lldb错误。这是我的初始设置和其他信息的代码。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    CCGLView *glView = [CCGLView viewWithFrame:[window_ bounds]
                               pixelFormat:kEAGLColorFormatRGB565   //kEAGLColorFormatRGBA8
                               depthFormat:0    //GL_DEPTH_COMPONENT24_OES
                        preserveBackbuffer:NO
                                sharegroup:nil
                             multiSampling:NO
                           numberOfSamples:0];
    [glView setMultipleTouchEnabled:YES];
    director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
    director_.wantsFullScreenLayout = YES;
    [director_ setDisplayStats:YES];
    [director_ setAnimationInterval:1.0/60];
    [director_ setView:glView];
    [director_ setDelegate:self];
    [director_ setProjection:kCCDirectorProjection2D];

     if( ! [director_ enableRetinaDisplay:YES] )
        CCLOG(@"Retina Display Not supported");

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

    // If the 1st suffix is not found and if fallback is enabled then fallback suffixes are going to searched. If none is found, it will try with the name without suffix.
    // On iPad HD  : "-ipadhd", "-ipad",  "-hd"
    // On iPad     : "-ipad", "-hd"
    // On iPhone HD: "-hd"
    CCFileUtils *sharedFileUtils = [CCFileUtils sharedFileUtils];
    [sharedFileUtils setEnableFallbackSuffixes:NO];             // Default: NO. No fallback suffixes are going to be used
    [sharedFileUtils setiPhoneRetinaDisplaySuffix:@"-hd"];      // Default on iPhone RetinaDisplay is "-hd"
    [sharedFileUtils setiPadSuffix:@"-ipad"];                   // Default on iPad is "ipad"
    [sharedFileUtils setiPadRetinaDisplaySuffix:@"-ipadhd"];    // Default on iPad RetinaDisplay is "-ipadhd"

    // Assume that PVR images have premultiplied alpha
    [CCTexture2D PVRImagesHavePremultipliedAlpha:YES];

    // and add the scene to the stack. The director will run it when it automatically when the view is displayed.
    [director_ pushScene: [IntroLayer scene]]; 


    // Create a Navigation Controller with the Director
    navController_ = [[UINavigationController alloc] initWithRootViewController:director_];
    navController_.navigationBarHidden = YES;

    // set the Navigation Controller as the root view controller
        // [window_ addSubview:navController_.view];    // Generates flicker.
    [window_ setRootViewController:navController_];

    // make main window visible
    [window_ makeKeyAndVisible];

    return YES;
} 

和init方法中的HeloworldLayer.m中的代码

- (id)init {

    if ((self=[super init])) {

        winSize = [CCDirector sharedDirector].winSize;

        CCSprite * background =[CCSprite spriteWithFile:@"Bg.png" rect:CGRectMake(0, 0, 1024, 768)];
        background.position=ccp(winSize.width/2, winSize.height/2); 
        [self addChild:background];

        CCSprite *bgstand=[CCSprite spriteWithFile:@"back_side.png"];
        bgstand.position=ccp(winSize.width/2, winSize.height/2-150);
        [self addChild:bgstand];

        CCSprite *wheel=[CCSprite spriteWithFile:@"wheel.png"];
        wheel.position=ccp(winSize.width/2, winSize.height/2+55);
        [self addChild:wheel];

        CCSprite *fgstand=[CCSprite spriteWithFile:@"front_side.png"];
        fgstand.position=ccp(winSize.width/2, winSize.height/2-150);
        [self addChild:fgstand];

    }
    return self;
}

当我运行我的代码时,我得到了这种日志

2013-05-23 17:04:06.045 Box2Dtry[2333:c07] cocos2d: OS version: 6.1 (0x06010000)
2013-05-23 17:04:06.046 Box2Dtry[2333:c07] cocos2d: GL_VENDOR:   Apple Computer, Inc.
2013-05-23 17:04:06.046 Box2Dtry[2333:c07] cocos2d: GL_RENDERER: Apple Software Renderer
2013-05-23 17:04:06.047 Box2Dtry[2333:c07] cocos2d: GL_VERSION:  OpenGL ES 2.0 APPLE
2013-05-23 17:04:06.047 Box2Dtry[2333:c07] cocos2d: GL_MAX_TEXTURE_SIZE: 4096
2013-05-23 17:04:06.048 Box2Dtry[2333:c07] cocos2d: GL_MAX_TEXTURE_UNITS: 8
2013-05-23 17:04:06.048 Box2Dtry[2333:c07] cocos2d: GL_MAX_SAMPLES: 4
2013-05-23 17:04:06.048 Box2Dtry[2333:c07] cocos2d: GL supports PVRTC: YES
2013-05-23 17:04:06.049 Box2Dtry[2333:c07] cocos2d: GL supports BGRA8888 textures: YES
2013-05-23 17:04:06.049 Box2Dtry[2333:c07] cocos2d: GL supports NPOT textures: YES
2013-05-23 17:04:06.049 Box2Dtry[2333:c07] cocos2d: GL supports discard_framebuffer: YES
2013-05-23 17:04:06.050 Box2Dtry[2333:c07] cocos2d: GL supports shareable VAO: NO
2013-05-23 17:04:06.050 Box2Dtry[2333:c07] cocos2d: compiled with Profiling Support: NO

2013-05-23 17:04:06.051 Box2Dtry[2333:c07] cocos2d: **** WARNING ****   CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h

 2013-05-23 17:04:06.098 Box2Dtry[2333:c07] cocos2d: cocos2d v2.0.0
 2013-05-23 17:04:06.098 Box2Dtry[2333:c07] cocos2d: Using Director   Type:CCDirectorDisplayLink
2013-05-23 17:04:06.114 Box2Dtry[2333:c07] cocos2d: animation started with frame interval: 60.00
2013-05-23 17:04:06.115 Box2Dtry[2333:c07] cocos2d: surface size: 2048x1536
2013-05-23 17:04:07.432 Box2Dtry[2333:c07] cocos2d: CCTexture2D: Using RGB565 texture since image has no alpha

1 个答案:

答案 0 :(得分:0)

因为在模拟器上启动了ipad视网膜,你可以在debug中看到:

2013-05-23 17:04:06.115 Box2Dtry[2333:c07] cocos2d: surface size: 2048x1536 //This is iPad retina

当您使用旧Mac从模拟器启动ipad视网膜时,您会发现一切都变慢了。 更改模拟器类型或硬件类型。