我已经使用 cocos2dx 为尺寸为 480*320 的设备制作了 android 构建并且它工作正常但是当我将相同的构建放在另一个尺寸为 640*480的 android 设备中时strong> 发生缩放问题....
我正在使用以下代码自动调整大小,但它不起作用:
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/