Cocos2D重置CCGLView帧大小

时间:2013-01-28 23:40:04

标签: xcode opengl-es cocos2d-iphone

我按照http://thurt1.rssing.com/browser.php?indx=1571098&last=1&item=1上的教程将Cocos2D视图集成到UITabBar的UIViewController中。

- (void)viewDidLoad {
[super viewDidLoad];

CCDirector *director = [CCDirector sharedDirector];

if([director isViewLoaded] == NO)
{
    // Create the OpenGL view that Cocos2D will render to.
    CCGLView *glView = [CCGLView viewWithFrame:[[[UIApplication sharedApplication] keyWindow] bounds]
                                   pixelFormat:kEAGLColorFormatRGB565
                                   depthFormat:0
                            preserveBackbuffer:NO
                                    sharegroup:nil
                                 multiSampling:NO
                               numberOfSamples:0];

    // Assign the view to the director.
    director.view = glView;

    // Initialize other director settings.
    [director setAnimationInterval:1.0f/60.0f];
    [director enableRetinaDisplay:YES];
}

// Set the view controller as the director's delegate, so we can respond to certain events.
director.delegate = self;

// Add the director as a child view controller of this view controller.
[self addChildViewController:director];

// Add the director's OpenGL view as a subview so we can see it.
[self.view addSubview:director.view];
[self.view sendSubviewToBack:director.view];

// Finish up our view controller containment responsibilities.
[director didMoveToParentViewController:self];

// Run whatever scene we'd like to run here.
if(director.runningScene)
    [director replaceScene:[MyScene scene]];
else
    [director runWithScene:[MyScene scene]];

}

在第一个标签视图中它可以正常工作。但是,当我切换到另一个选项卡视图时,我需要调整CCGLView的大小以拥有它自己的动画层。我在检查是否已经有一个正在运行的场景之后尝试实现它:

 director.view.frame = CGRectMake(self.myNewView.bounds.origin.x, self.myNewView.bounds.origin.y, self.myNewView.bounds.size.width, self.myNewView.bounds.size.height);

但是当我在iphone设备上进行测试时,在两个标签之间进行切换时会抛出很多OpenGL错误(虽然在来回切换标签时动画层的背景颜色为黑色,但在模拟器上没有)。

2013-01-28 18:33:47.684 TestApp[43901:707] failed to call context
2013-01-28 18:33:47.686 TestApp[43901:707] cocos2d: surface size: 640x472
2013-01-28 18:33:47.687 TestApp[43901:707] Failed to make complete framebuffer object 0x8CDD
OpenGL error 0x0506 in -[CCSprite draw] 532
OpenGL error 0x0506 in -[CCSprite draw] 532
OpenGL error 0x0506 in -[CCSprite draw] 532
OpenGL error 0x0506 in -[CCSprite draw] 532

一旦初始化,Cocos2D中是否无法更改CCGLView的帧大小?或者在使用动画层切换不同的UIViews时是否有一些解决方法?非常感谢任何见解!

0 个答案:

没有答案