android - 在 cocos2dx 中自动调整大小

标签 android ios cocos2d-iphone cocos2d-x

我已经使用 cocos2dx 为尺寸为 480*320 的设备制作了 android 构建并且它工作正常但是当我将相同的构建放在另一个尺寸为 640*480 发生缩放问题....

我正在使用以下代码自动调整大小,但它不起作用:

AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello Lua");
eglView.setFrameSize(480, 320);

// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320);

最佳答案

首先,您粘贴的代码来自 main.cpp 文件,当您为 android 或 windows phone 或 ios 编译应用程序时,该文件不会发挥作用。该文件用于 win32 项目。

现在, 对于应用程序的自动缩放,AppDelegate.cpp 中的函数应该设置设计分辨率和策略。我使用 ExactFit 策略,因为它会拉伸(stretch)应用程序以填满整个屏幕区域,并且它适用于 Android、Windows、iOS 一切(我开发了应用程序并进行了测试):

bool AppDelegate::applicationDidFinishLaunching()
{
    // initialize director
    CCDirector *pDirector = CCDirector::sharedDirector();
    pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
    // turn on display FPS
    CCEGLView::sharedOpenGLView()->setDesignResolutionSize(1200, 720, kResolutionExactFit);
    pDirector->setDisplayStats(false);

    pDirector->setAnimationInterval(1.0 / 60);

    CCScene *pScene = HelloWorld::scene();

    pDirector->runWithScene(pScene);
    return true;
}

您还应该看看 this Detailed explanation of multi-resolution support更好地理解它。

关于android - 在 cocos2dx 中自动调整大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11683036/

相关文章:

android - 当应用程序在后台时将用户位置更新到服务器

android - 如何显示安装在 Android 设备上的应用商店列表?

android - 如何在移动设备上安全地存储数据?

objective-c - 声明包含 C++ 类类型 ivar 的 obj-c 类接口(interface)

Android、Skia 和硬件加速图形

ios - 如何为 Storyboard初始化的开关按钮设置默认 boolean 值

ios - UICollectionView 的 scrollToItem 没有调用 targetContentOffset

ios - 为什么 AVSampleBufferDisplayLayer 因操作中断 (-11847) 而失败?

android - 用于游戏开发的 cocos2d-iphone 或 cocos2d-x?

ios - Cocos2d 中的动画 Sprite 表