mirror of https://github.com/axmolengine/axmol.git
Allowing resolution being sent to CocosBuilder to be set by AppDelegate
This commit is contained in:
parent
6fdbff537a
commit
f050fc9f08
|
@ -65,26 +65,30 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
CCSize designSize = CCSizeMake(320, 480);
|
||||
CCSize resourceSize = CCSizeMake(320, 480);
|
||||
|
||||
|
||||
string res = "xlarge";
|
||||
if (screenSize.height > 1024)
|
||||
{
|
||||
resourceSize = CCSizeMake(1280, 1920);
|
||||
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-xlarge"), CCString::create(""), NULL));
|
||||
res = "xlarge";
|
||||
}
|
||||
else if (screenSize.height > 960)
|
||||
{
|
||||
resourceSize = CCSizeMake(640, 960);
|
||||
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-large"), CCString::create(""), NULL));
|
||||
res = "large";
|
||||
}
|
||||
else if (screenSize.height > 480)
|
||||
{
|
||||
resourceSize = CCSizeMake(480, 720);
|
||||
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-medium"), CCString::create(""), NULL));
|
||||
res = "medium";
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceSize = CCSizeMake(320, 568);
|
||||
CCFileUtils::sharedFileUtils()->setSearchResolutionsOrder(CCArray::create(CCString::create("resources-small"), CCString::create(""), NULL));
|
||||
res = "small";
|
||||
}
|
||||
|
||||
pDirector->setContentScaleFactor(resourceSize.height/designSize.height);
|
||||
|
@ -93,6 +97,8 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
|
||||
CCFileUtils::sharedFileUtils()->setSearchPath(CCArray::create(CCString::create(CCFileUtils::sharedFileUtils()->getWriteablePath()),
|
||||
CCString::create("assets/"), CCString::create(""), NULL));
|
||||
|
||||
PlayerStatus::setDeviceResolution(res);
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
#define SOCKET_CLASS_NAME "org/cocos2dx/cocosplayer/CocosPlayerSocket"
|
||||
#define STREAM_CLASS_NAME "org/cocos2dx/cocosplayer/CCBStreamHandler"
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace std;
|
||||
|
@ -30,4 +31,14 @@ extern "C" {
|
|||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
|
||||
void setDeviceResolutionJNI(const char *res) {
|
||||
JniMethodInfo t;
|
||||
if (JniHelper::getStaticMethodInfo(t, STREAM_CLASS_NAME, "setDeviceResolution", "(Ljava/lang/String;)V")) {
|
||||
jstring stringArg1 = t.env->NewStringUTF(res);
|
||||
t.env->CallStaticVoidMethod(t.classID, t.methodID, stringArg1);
|
||||
t.env->DeleteLocalRef(stringArg1);
|
||||
t.env->DeleteLocalRef(t.classID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
|||
extern "C" {
|
||||
extern void setPairingCodeJNI(int code);
|
||||
extern void cleanCacheDirJNI();
|
||||
extern void setDeviceResolutionJNI(const char* res);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -46,6 +46,10 @@ SEL_MenuHandler PlayerStatus::onResolveCCBCCMenuItemSelector(CCObject * pTarget,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
void PlayerStatus::setDeviceResolution(std::string res) {
|
||||
setDeviceResolutionJNI(res.c_str());
|
||||
}
|
||||
|
||||
void editBoxCallbackFunc(const char* pText, void* ctx)
|
||||
{
|
||||
PlayerStatus *thiz = (PlayerStatus *)ctx;
|
||||
|
|
|
@ -41,6 +41,7 @@ public:
|
|||
void pressedReset(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
void pressedRun(CCObject * pSender, cocos2d::extension::CCControlEvent pCCControlEvent);
|
||||
static void loadMainScene(const char *fileName);
|
||||
static void setDeviceResolution(std::string res);
|
||||
|
||||
cocos2d::CCMenuItemImage* mBtnRun;
|
||||
cocos2d::CCMenuItemImage* mBtnReset;
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.nio.ByteOrder;
|
|||
|
||||
public class CCBStreamHandler {
|
||||
|
||||
private static String resolution = "xlarge";
|
||||
public static final String TAG = CocosPlayerSocket.class.getSimpleName();
|
||||
|
||||
public static NSDictionary parseBinaryPLIST(InputStream is) {
|
||||
|
@ -95,7 +96,7 @@ public class CCBStreamHandler {
|
|||
root.put("cmd", "deviceinfo");
|
||||
root.put("devicename", android.os.Build.MODEL);
|
||||
root.put("devicetype", "Android");
|
||||
root.put("preferredresourcetype", "xlarge");
|
||||
root.put("preferredresourcetype", resolution);
|
||||
String payload = root.toXMLPropertyList();
|
||||
|
||||
// String data = new String(header, 0 , header.length);
|
||||
|
@ -104,4 +105,13 @@ public class CCBStreamHandler {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setDeviceResolution(String res) {
|
||||
CocosPlayerSocket server = new CocosPlayerSocket();
|
||||
Log.i(TAG, "Starting with resolution: "+res);
|
||||
resolution = res;
|
||||
server.setContext(CocosPlayer.c);
|
||||
server.createServer();
|
||||
}
|
||||
|
||||
}
|
|
@ -27,15 +27,15 @@ import org.cocos2dx.lib.Cocos2dxActivity;
|
|||
|
||||
import android.os.Bundle;
|
||||
import android.content.Intent;
|
||||
import android.content.ContextWrapper;
|
||||
import android.content.Context;
|
||||
|
||||
public class CocosPlayer extends Cocos2dxActivity{
|
||||
|
||||
public static Context c;
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
CocosPlayerSocket server = new CocosPlayerSocket();
|
||||
server.setContext(getApplicationContext());
|
||||
server.createServer();
|
||||
c = getApplicationContext();
|
||||
}
|
||||
|
||||
static {
|
||||
|
|
Loading…
Reference in New Issue