问题描述
当我从根视图控制器的 init 方法调用 cocos2d 中的 CGSize winSize = [[CCDirector sharedDirector]winSize];
并在它报告屏幕为纵向后立即调用 nslog "winSize"实际上它在风景中.当您从 -(void)onEnter 或从根视图加载的视图中调用它时,不会发生此错误.我看到其他一些人在谷歌搜索问题后遇到了这个问题,但没有人真正知道如何解决它,或者答案不适用于我.
When I call CGSize winSize = [[CCDirector sharedDirector]winSize];
in cocos2d from the init method of the root view controller and nslog "winSize" right after it reports that the screen is in portrait when in fact its in landscape. This error doesn't occur when you call it from -(void)onEnter or from a view that was loaded from the root view. I see that a few other people are having this problem after googling the problem but no one really seams to know how to fix it or the answer doesn't apply to me.
推荐答案
是的,这是 cocos2D 2.0 中的严重问题之一.当我尝试第一个场景的 init 方法时.
Yes, This is one of the serious problem in cocos2D 2.0. When I try in init method of first scene.
而不是 init 尝试 onEnter.
Instead of init try onEnter.
-(void)onEnter
{
[super onEnter];
CGSize winSize = [[CCDirector sharedDirector]winSize];
//Place all your init functions here.
}
注意:在 iphone5 中,缺少 Default-568h@2x.png 也会导致尺寸错误!!!Cocos2d 3.0:
Note: In iphone5, missing Default-568h@2x.png also result wrong size!!! Cocos2d 3.0:
CGSize s = [[CCDirector sharedDirector] viewSize];
CGSize s = [[CCDirector sharedDirector] viewSize];
这篇关于[[CCDirector sharedDirector]winSize] 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!