Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

ios - [[CCDirector sharedDirector]winSize] is wrong

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Yes, This is one of the serious problem in cocos2D 2.0. When I try in init method of first scene.

Instead of init try onEnter.

-(void)onEnter
{
  [super onEnter];
  CGSize winSize = [[CCDirector sharedDirector]winSize];

  //Place all your init functions here.
}

Note: In iphone5, missing Default-568h@2x.png also result wrong size!!! Cocos2d 3.0:

CGSize s = [[CCDirector sharedDirector] viewSize];


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...