Reputation: 23407
I am running my cocos2d program on simulator. It works fine but when I run it on device, it throws error OpenGL error 0x0506 in -[CCSprite draw] 530 and [CCGLView swapBuffers] 283. In my program I want to push one scene to another scene.At that time it shows error and black screen of the next scene.Please help me about it. I also tried to google it.
Note : My apps is not crash but problem to draw sprite.
My Code As below:
First Load LoadingLayer as below.
-(void) directorDidReshapeProjection:(CCDirector*)director
{
if ([[director runningScene] isRunning])
{
[[CCDirector sharedDirector] replaceScene:[HelloWorldLayer scene]];
}
else
{
[[CCDirector sharedDirector] runWithScene:[LoadingLayer scene]];
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Create the main window
window_ = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[self.window setBackgroundColor:[UIColor whiteColor]];
glView = [CCGLView viewWithFrame:[window_ bounds]
pixelFormat:kEAGLColorFormatRGB565
depthFormat:0
preserveBackbuffer:NO
sharegroup:nil
multiSampling:NO
numberOfSamples:0];
director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
director_.wantsFullScreenLayout = YES;
// Display FSP and SPF
[director_ setDisplayStats:NO];
// set FPS at 60
[director_ setAnimationInterval:1.0/60];
// attach the openglView to the director
[director_ setView:glView];
// 2D projection
[director_ setProjection:kCCDirectorProjection2D];
// [director setProjection:kCCDirectorProjection3D];
// 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");
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change this setting at any time.
[CCTexture2D setDefaultAlphaPixelFormat:kCCTexture2DPixelFormat_RGBA8888];
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];
// Create a Navigation Controller with the Director
navController_ = [[MyNavigationController alloc] initWithRootViewController:director_];
navController_.navigationBarHidden = YES;
// for rotation and other messages
[director_ setDelegate:navController_];
// set the Navigation Controller as the root view controller
[window_ setRootViewController:navController_];
// make main window visible
[window_ makeKeyAndVisible];
return YES;
}
After LoadingLayer it push to viewcontroller.it has button click on it go to HelloWorldLayer.
-(void)Button
{
director_ = (CCDirectorIOS*) [CCDirector sharedDirector];
[director_ replaceScene:[HelloWorldLayer scene]];
[self.navigationController pushViewController:director_ animated:YES];
}
flow as scene to viewcontroller to scene.
app is not crash but it got error as below
on Simulator it run good but CPU uses reach 95% to 100%.
Upvotes: 1
Views: 2149
Reputation: 13999
but afer that scene i go to viewcontroller
If you want to use UIKit and Cocos2d for iPhone at the same time, I highly recommend you to read attachDemo to achieve the goal.
https://github.com/cocos2d/cocos2d-iphone/tree/master-v2/tests/attachDemo
Upvotes: 0
Reputation: 1042
This is just a cocos2d application and not a UIKit hybrid right? In that case why are you calling pushViewController when you are simply just switching the scene (CCScene)? Try removing:
[self.navigationController pushViewController:director_ animated:YES];
There is no reason you should be pushing the director, it is already present. When you are switching CCScene's you are not creating a new view controller.
Upvotes: 5