[[CCDirector sharedDirector]winSize] 错误

[[CCDirector sharedDirector]winSize] is wrong([[CCDirector sharedDirector]winSize] 错误)
本文介绍了[[CCDirector sharedDirector]winSize] 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从根视图控制器的 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] 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Get an event when UIBarButtonItem menu is displayed(显示UIBarButtonItem菜单时获取事件)