mirror of https://github.com/axmolengine/axmol.git
Fixing rotation for iOS
This commit is contained in:
parent
0378a97fa0
commit
cecb157f22
|
@ -19,6 +19,8 @@
|
|||
char *_js_log_buf_ccbuilder = NULL;
|
||||
static bool firstTime = true;
|
||||
|
||||
static bool isPortraitApp = true;
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
CCScene *mainScene;
|
||||
|
@ -54,6 +56,7 @@ bool runMainScene() {
|
|||
|
||||
void handle_ccb_run() {
|
||||
CCFileUtils::sharedFileUtils()->purgeCachedEntries();
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
CCFileUtils::sharedFileUtils()->loadFilenameLookupDictionaryFromFile("fileLookup.plist");
|
||||
ScriptingCore::getInstance()->runScript("main.js");
|
||||
}
|
||||
|
@ -76,13 +79,14 @@ void initViews(CCSize designSize) {
|
|||
static void setViewValues(CCEGLView *pView, CCSize frameSize, CCSize designSize) {
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
(CCScriptEngineManager::sharedManager())->removeScriptEngine();
|
||||
resetCocosApp();
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
|
||||
pView->setFrameSize(frameSize.height, frameSize.width);
|
||||
pView->setDesignResolutionSize(designSize.height, designSize.width, kResolutionNoBorder);
|
||||
CCLOG("Design Size %f x %f", designSize.height, designSize.width);
|
||||
CCLOG("Design Size %f x %f frame: %%f x %f", designSize.height, designSize.width, frameSize.height, frameSize.width);
|
||||
cocos2d::CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
|
||||
}
|
||||
|
||||
|
@ -98,9 +102,24 @@ void handle_set_orient(bool isPortrait) {
|
|||
setViewValues(pView, frameSize, designSize);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void handle_set_orient(float w, float h) {
|
||||
cocos2d::CCEGLView* pView = CCEGLView::sharedOpenGLView();
|
||||
bool isPortrait = (w > h) ? false: true;
|
||||
if (pView != NULL)
|
||||
{
|
||||
CCSize frameSize = CCSizeMake(w, h);
|
||||
CCSize designSize = pView->getDesignResolutionSize();
|
||||
CCLOG("is Portrait %d", isPortrait);
|
||||
if (((frameSize.width > frameSize.height && isPortrait))
|
||||
|| (frameSize.width < frameSize.height && !isPortrait)) {
|
||||
setViewValues(pView, frameSize, designSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void handle_set_message(const char* msg) {
|
||||
CCBHelper::setInstructionsMessage(msg);
|
||||
}
|
||||
|
@ -114,6 +133,7 @@ void handle_disconnected() {
|
|||
}
|
||||
|
||||
void handle_ccb_stop() {
|
||||
SimpleAudioEngine::sharedEngine()->end();
|
||||
runMainScene();
|
||||
}
|
||||
|
||||
|
@ -191,7 +211,7 @@ extern "C" {
|
|||
if (screenSize.height > 1136)
|
||||
{
|
||||
res = "iPad";
|
||||
setResolutionSizes(true, true, true);
|
||||
setResolutionSizes(true, true, isPortraitApp);
|
||||
resDirOrders.push_back("resources-ipadhd");
|
||||
resDirOrders.push_back("resources-ipad");
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
|
@ -200,7 +220,7 @@ extern "C" {
|
|||
cocos2d::extension::CCBReader::setResolutionScale(2);
|
||||
} else if(screenSize.height > 1024) {
|
||||
res = "iPhone";
|
||||
setResolutionSizes(false, true, true);
|
||||
setResolutionSizes(false, true, isPortraitApp);
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
isIPhone = true;
|
||||
|
@ -209,7 +229,7 @@ extern "C" {
|
|||
else if (screenSize.height > 960)
|
||||
{
|
||||
res = "iPad";
|
||||
setResolutionSizes(true, false, true);
|
||||
setResolutionSizes(true, false, isPortraitApp);
|
||||
resDirOrders.push_back("resources-ipad");
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
isIPhone = false;
|
||||
|
@ -220,7 +240,7 @@ extern "C" {
|
|||
else if (screenSize.height > 480)
|
||||
{
|
||||
res = "iPhone";
|
||||
setResolutionSizes(false, true, true);
|
||||
setResolutionSizes(false, true, isPortraitApp);
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
isIPhone = true;
|
||||
|
@ -229,7 +249,7 @@ extern "C" {
|
|||
else
|
||||
{
|
||||
res = "iPhone";
|
||||
setResolutionSizes(false, false, true);
|
||||
setResolutionSizes(false, false, isPortraitApp);
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
isIPhone = true;
|
||||
isRetina = false;
|
||||
|
@ -244,14 +264,14 @@ extern "C" {
|
|||
if(dpi > 300) { // retina
|
||||
if (screenSize.height > 1920) {
|
||||
res = "xlarge";
|
||||
setResolutionSizes(true, true, true);
|
||||
setResolutionSizes(true, true, isPortraitApp);
|
||||
resDirOrders.push_back("resources-xlarge");
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
} else {
|
||||
res = "large";
|
||||
setResolutionSizes(false, true, true);
|
||||
setResolutionSizes(false, true, isPortraitApp);
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
|
@ -260,7 +280,7 @@ extern "C" {
|
|||
if (screenSize.height > 960)
|
||||
{
|
||||
res = "large";
|
||||
setResolutionSizes(true, false, true);
|
||||
setResolutionSizes(true, false, isPortraitApp);
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
|
@ -268,19 +288,19 @@ extern "C" {
|
|||
else if (screenSize.height > 768)
|
||||
{
|
||||
res = "medium";
|
||||
setResolutionSizes(true, false, true);
|
||||
setResolutionSizes(true, false, isPortraitApp);
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else if (screenSize.height > 480)
|
||||
{
|
||||
res = "small";
|
||||
setResolutionSizes(false, false, true);
|
||||
setResolutionSizes(false, false, isPortraitApp);
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else
|
||||
{
|
||||
setResolutionSizes(false, false, true);
|
||||
setResolutionSizes(false, false, isPortraitApp);
|
||||
res = "xsmall";
|
||||
resDirOrders.push_back("resources-xsmall");
|
||||
}
|
||||
|
@ -289,8 +309,7 @@ extern "C" {
|
|||
|
||||
CCFileUtils *pFileUtils = CCFileUtils::sharedFileUtils();
|
||||
pFileUtils->setSearchResolutionsOrder(resDirOrders);
|
||||
|
||||
|
||||
|
||||
std::vector<std::string> searchPaths = pFileUtils->getSearchPaths();
|
||||
searchPaths.insert(searchPaths.begin(), pFileUtils->getWritablePath());
|
||||
pFileUtils->setSearchPaths(searchPaths);
|
||||
|
|
|
@ -43,6 +43,7 @@ public:
|
|||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
void shit();
|
||||
|
||||
};
|
||||
|
||||
|
@ -52,6 +53,7 @@ void handle_ccb_stop();
|
|||
void handle_connected();
|
||||
void handle_disconnected();
|
||||
void handle_set_orient(bool isPortrait);
|
||||
void handle_set_orient(float w, float h);
|
||||
void handle_set_message(const char *msg);
|
||||
void handle_set_status(const char *msg);
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "AppDelegate.h"
|
||||
#import "CCBDirectoryComparer.h"
|
||||
#import "SSZipArchive.h"
|
||||
#import "RootViewController.h"
|
||||
|
||||
// Predefined messages
|
||||
NSString *kCCBNetworkStatusStringWaiting = @"Waiting for connections";
|
||||
|
@ -411,7 +412,13 @@ NSString *kCCBPlayerStatusStringScript = @"Action: Executing script";
|
|||
if ([[arr objectAtIndex:1] boolValue]) orientations |= UIInterfaceOrientationMaskPortraitUpsideDown;
|
||||
if ([[arr objectAtIndex:2] boolValue]) orientations |= UIInterfaceOrientationMaskLandscapeLeft;
|
||||
if ([[arr objectAtIndex:3] boolValue]) orientations |= UIInterfaceOrientationMaskLandscapeRight;
|
||||
|
||||
|
||||
[RootViewController setDeviceOrientation:orientations];
|
||||
if([[arr objectAtIndex:2] boolValue] || [[arr objectAtIndex:3] boolValue]) {
|
||||
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeLeft];
|
||||
} else {
|
||||
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
|
||||
}
|
||||
handle_set_orient(([[arr objectAtIndex:0] boolValue] || [[arr objectAtIndex:1] boolValue]) ? true: false);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,6 +51,7 @@ extern "C" {
|
|||
void resetCocosApp() {
|
||||
[[AppController appController] resetCocos2d];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -73,8 +74,18 @@ static AppController* appController = NULL;
|
|||
- (void) resetCocos2d
|
||||
{
|
||||
|
||||
UIView* mainView = viewController.view.superview;
|
||||
[viewController.view removeFromSuperview];
|
||||
return;
|
||||
|
||||
UIView *view = [window.subviews objectAtIndex:0];
|
||||
[view removeFromSuperview];
|
||||
[window addSubview:view];
|
||||
|
||||
UIView* mainView = viewController.view.superview;
|
||||
// [viewController.view removeFromSuperview];
|
||||
// [mainView addSubview:viewController.view];
|
||||
|
||||
return;
|
||||
|
||||
viewController = nil;
|
||||
cocos2d::CCDirector::sharedDirector()->end();
|
||||
|
||||
|
|
|
@ -25,9 +25,13 @@
|
|||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
static NSUInteger deviceOrientations = 0;
|
||||
|
||||
@interface RootViewController : UIViewController {
|
||||
|
||||
}
|
||||
|
||||
//@property (nonatomic, assign) NSUInteger deviceOrientations;
|
||||
|
||||
+ (void) setDeviceOrientation: (NSUInteger) oreintation;
|
||||
@end
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
@implementation RootViewController
|
||||
|
||||
//@synthesize deviceOrientations;
|
||||
/*
|
||||
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
|
@ -36,10 +37,15 @@
|
|||
// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead
|
||||
- (NSUInteger) supportedInterfaceOrientations{
|
||||
#ifdef __IPHONE_6_0
|
||||
return UIInterfaceOrientationMaskAllButUpsideDown;
|
||||
return deviceOrientations;
|
||||
#endif
|
||||
}
|
||||
|
||||
+ (void) setDeviceOrientation: (NSUInteger) orientation {
|
||||
deviceOrientations = orientation;
|
||||
}
|
||||
|
||||
|
||||
- (BOOL) shouldAutorotate {
|
||||
return YES;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue