//cocos2dx 获取IOS 分辨率 然后传给Lua
IOS代码:
+(NSString*) getHostResolving
{}
+ (NSString*) getHostResolving
{
return [Utils getHostResolving];
}
Lua:
--获取屏幕分辨率
function Bridge_ios.getClientResolving()
local sigs = "()Ljava/lang/String;"
local ok,ret = luaoc.callStaticMethod(BRIDGE_CLASS,"getHostResolving")
if not ok then
print("luajssssssssssssssssssss error:" .. ret)
return ""
else
print("gggggggggggggggggggggggggggggggggis:" .. ret)
return ret
end
end--
、、android代码如下:
// 分辨率全局变量
static int w = -1;
// 分辨率
static int h = -1;
在AppActivity的onCreate里加
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
w = width;
h = height;
public static String getHostResolving() throws JSONException
{
//2.Set the format of windo
int[] data = new int[2];
data[0] = w;
data[1] = h;
Log.i(TAG, "-> " + w); //统一TAG
Log.i(TAG, "-> " + h); //统一TAG
//JsonObject object = new JsonObject();
JSONObject jsonObject = new JSONObject();
jsonObject.put("width",w );
jsonObject.put("height",h);
return jsonObject.toString();
}
lua:
--获取屏幕分辨率
function Bridge_android.getClientResolving()
local sigs = "()Ljava/lang/String;"
local ok,ret = luaj.callStaticMethod(BRIDGE_CLASS,"getHostResolving",{},sigs)
if not ok then
print("luajssssssssssssssssssss error:" .. ret)
return ""
else
print("gggggggggggggggggggggggggggggggggis:" .. ret)
return ret
end
end-
获取:
function MultiPlatform:getHostResolving()
local plat = self:getSupportPlatform()
if nil ~= g_var(PLATFORM[plat]) and nil ~= g_var(PLATFORM[plat]).getClientResolving then
return g_var(PLATFORM[plat]).getClientResolving()
else
print("unknow platform ==> " .. plat)
return ""
end
end
local fenbian = MultiPlatform:getInstance():getHostResolving()
local jsonStr = cjson.decode(fenbian)
print("88888888888888888888888555",jsonStr.width,jsonStr.height)