cocos2dx 怎么获得android屏幕分辨率
推荐于2016-01-03 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517198
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
写一个ViewAutoScale函数,如下:
#include "ViewAutoScale.h"
USING_NS_CC;
bool IsMatchDisplay(int w, int h, CCSize& size )
{
return (w==size.width && h==size.height) || (h==size.width && w==size.height);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
if(view == NULL)
{
return -1;
}
for (int i=0; i < displays; i++)
{
if (IsMatchDisplay(width, height, supportDisplay[i]))
{
view->Create((LPCTSTR)title, width, height);
return i+1;
}
}
view->Create((LPCTSTR)title, defaultWidth, defaultHeight);
view->setScreenScale(min((float)width/ defaultWidth, (float)height/ defaultHeight));
view->resize(width, height);
view->centerWindow();
return 0;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
if(view == NULL)
{
return -1;
}
for (int i=0; i < displays; i++)
{
if (IsMatchDisplay(width, height, supportDisplay[i]))
{
return i+1;
}
}
view->create(defaultWidth, defaultHeight);
return 0;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
return 0;
}
#endif
修改jni/helloworld/main.cpp文件:
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
cocos2d::CCSize sSupportDisplay[]={cocos2d::CCSize(480, 320)};
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
{
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
view->setFrameWidthAndHeight(w, h);
// if you want to run in WVGA with HVGA resource, set it
ViewAutoScale(view,
NULL,
w,
h,
sSupportDisplay,
sizeof(sSupportDisplay)/sizeof(CCSize),
480, 320);
#include "ViewAutoScale.h"
USING_NS_CC;
bool IsMatchDisplay(int w, int h, CCSize& size )
{
return (w==size.width && h==size.height) || (h==size.width && w==size.height);
}
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
if(view == NULL)
{
return -1;
}
for (int i=0; i < displays; i++)
{
if (IsMatchDisplay(width, height, supportDisplay[i]))
{
view->Create((LPCTSTR)title, width, height);
return i+1;
}
}
view->Create((LPCTSTR)title, defaultWidth, defaultHeight);
view->setScreenScale(min((float)width/ defaultWidth, (float)height/ defaultHeight));
view->resize(width, height);
view->centerWindow();
return 0;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
if(view == NULL)
{
return -1;
}
for (int i=0; i < displays; i++)
{
if (IsMatchDisplay(width, height, supportDisplay[i]))
{
return i+1;
}
}
view->create(defaultWidth, defaultHeight);
return 0;
}
#endif
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
int ViewAutoScale(cocos2d::CCEGLView* view,
void* title,
int width,
int height,
cocos2d::CCSize* supportDisplay,
int displays,
int defaultWidth,
int defaultHeight)
{
return 0;
}
#endif
修改jni/helloworld/main.cpp文件:
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
{
cocos2d::CCSize sSupportDisplay[]={cocos2d::CCSize(480, 320)};
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
{
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
view->setFrameWidthAndHeight(w, h);
// if you want to run in WVGA with HVGA resource, set it
ViewAutoScale(view,
NULL,
w,
h,
sSupportDisplay,
sizeof(sSupportDisplay)/sizeof(CCSize),
480, 320);
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家可靠的代理服务提供商,提供原生IP(住宅原生IP)和高匿名代理服务。以下是关于StormProxies的原生IP服务的一些信息:1. 住宅原生IP:StormProxies提供的住宅原生IP是指从真实的家庭或企...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询