Hi!
I need my programm to rotate using function "willAnimateRotationToInterfaceOrientation: ...".
And I create window and veiw from this.
In my veiw class I want CCDirector to be updated with new options.
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration{
NSLog(@"rotate ");
CGRect contentRect = CGRectMake(0, 0, 480, 320);
self.view.center=ccp(160,240);
self.view.bounds = contentRect;
[[CCDirector sharedDirector] detach];
[[CCDirector sharedDirector] attachInView:self.view withFrame:CGRectMake(0, 0, 480, 320)];
[[CCDirector sharedDirector] setDeviceOrientation:interfaceOrientation];
[[CCDirector sharedDirector] replaceScene:[HelloWorld scene]];
}
Initialize CCDirector:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window addSubview:viewController.view];
// cocos2d will inherit these values
[window setUserInteractionEnabled:YES];
[window setMultipleTouchEnabled:YES];
// Try to use CADisplayLink director
// if it fails (SDK < 3.1) use the default director
if( ! [CCDirector setDirectorType:CCDirectorTypeDisplayLink] )
[CCDirector setDirectorType:CCDirectorTypeDefault];
// Use RGBA_8888 buffers
// Default is: RGB_565 buffers
[[CCDirector sharedDirector] setPixelFormat:kPixelFormatRGBA8888];
// Create a depth buffer of 16 bits
// Enable it if you are going to use 3D transitions or 3d objects
[[CCDirector sharedDirector] setDepthBufferFormat:kDepthBuffer16];
// Default texture format for PNG/BMP/TIFF/JPEG/GIF images
// It can be RGBA8888, RGBA4444, RGB5_A1, RGB565
// You can change anytime.
[CCTexture2D setDefaultAlphaPixelFormat:kTexture2DPixelFormat_RGBA8888];
// before creating any layer, set the landscape mode
//[[CCDirector sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
[[CCDirector sharedDirector] setAnimationInterval:1.0/60];
[[CCDirector sharedDirector] setDisplayFPS:YES];
// create an openGL view inside a window
[[CCDirector sharedDirector] attachInView:viewController.view];
[window makeKeyAndVisible];
[[CCDirector sharedDirector] runWithScene: [HelloWorld scene]];
// Add the view controller's view to the window and display.
CGSize size;
size = [[CCDirector sharedDirector] winSize];
NSInteger width, height;
width = size.width;
height = size.height;
NSLog(@"window 0:%i %i", width, height);
return YES;
}
But I see pink screen.
Any idea what I might be doing wrong?
Regards,
Riddick.