mirror of https://github.com/axmolengine/axmol.git
Adding rudementary support for Rotation in iOS
This commit is contained in:
parent
d8c30e0c5b
commit
bb91f1eb30
|
@ -15,6 +15,7 @@
|
|||
|
||||
|
||||
char *_js_log_buf_ccbuilder = NULL;
|
||||
static bool firstTime = true;
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
@ -38,9 +39,12 @@ bool runMainScene() {
|
|||
transitionColor.b = 0;
|
||||
|
||||
mainScene = PlayerStatus::loadMainScene("StatusLayer.ccbi");
|
||||
if(CCDirector::sharedDirector()->getRunningScene() != NULL) {
|
||||
|
||||
if(CCDirector::sharedDirector()->getRunningScene() != NULL && CCDirector::sharedDirector()->getRunningScene() != mainScene) {
|
||||
CCDirector::sharedDirector()->replaceScene(CCTransitionFade::create(0.5f, mainScene, transitionColor));
|
||||
} else {
|
||||
} else if(CCDirector::sharedDirector()->getRunningScene() != NULL) {
|
||||
|
||||
}else {
|
||||
CCDirector::sharedDirector()->runWithScene(CCTransitionFade::create(0.5f, mainScene, transitionColor));
|
||||
}
|
||||
return true;
|
||||
|
@ -56,8 +60,43 @@ void handle_connected() {
|
|||
CCBHelper::setStatusMessage("Connected!");
|
||||
}
|
||||
|
||||
void resetCocosApp();
|
||||
|
||||
void initViews(CCSize designSize) {
|
||||
(CCScriptEngineManager::sharedManager())->removeScriptEngine();
|
||||
resetCocosApp();
|
||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
||||
pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
|
||||
pDirector->setProjection(kCCDirectorProjection2D);
|
||||
CCEGLView::sharedOpenGLView()->setDesignResolutionSize(designSize.width, designSize.height, kResolutionNoBorder);
|
||||
}
|
||||
|
||||
static void setViewValues(CCEGLView *pView, CCSize frameSize, CCSize designSize) {
|
||||
|
||||
//#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
// (CCScriptEngineManager::sharedManager())->removeScriptEngine();
|
||||
// resetCocosApp();
|
||||
//#endif
|
||||
//
|
||||
pView->setFrameSize(frameSize.height, frameSize.width);
|
||||
pView->setDesignResolutionSize(designSize.height, designSize.width, kResolutionNoBorder);
|
||||
CCLOG("Design Size %f x %f", designSize.height, designSize.width);
|
||||
cocos2d::CCDirector::sharedDirector()->setProjection(kCCDirectorProjection2D);
|
||||
}
|
||||
|
||||
void handle_set_orient(bool isPortrait) {
|
||||
CCLOG("ORIENTATION HALF IMPLEMENTED");
|
||||
cocos2d::CCEGLView* pView = CCEGLView::sharedOpenGLView();
|
||||
if (pView != NULL)
|
||||
{
|
||||
CCSize frameSize = pView->getFrameSize();
|
||||
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) {
|
||||
|
@ -99,6 +138,7 @@ extern "C" {
|
|||
|
||||
const char * getCCBDirectoryPath();
|
||||
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
|
||||
|
@ -231,7 +271,12 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
|
||||
CCScriptEngineProtocol *pEngine = ScriptingCore::getInstance();
|
||||
CCScriptEngineManager::sharedManager()->setScriptEngine(pEngine);
|
||||
runMainScene();
|
||||
if(firstTime) {
|
||||
runMainScene();
|
||||
firstTime = false;
|
||||
} else {
|
||||
handle_ccb_run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ NSString *kCCBPlayerStatusStringScript = @"Action: Executing script";
|
|||
if ([[arr objectAtIndex:2] boolValue]) orientations |= UIInterfaceOrientationMaskLandscapeLeft;
|
||||
if ([[arr objectAtIndex:3] boolValue]) orientations |= UIInterfaceOrientationMaskLandscapeRight;
|
||||
|
||||
//[AppController appController].deviceOrientations = orientations;
|
||||
handle_set_orient(([[arr objectAtIndex:0] boolValue] || [[arr objectAtIndex:1] boolValue]) ? true: false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,8 @@ void cleanCache() {
|
|||
UIWindow *window;
|
||||
RootViewController *viewController;
|
||||
}
|
||||
+ (AppController*) appController;
|
||||
- (void) resetCocos2d;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
ServerController *server;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
|
||||
|
@ -46,6 +47,10 @@ extern "C" {
|
|||
return [dirPath cStringUsingEncoding:NSASCIIStringEncoding];
|
||||
}
|
||||
|
||||
void resetCocosApp() {
|
||||
[[AppController appController] resetCocos2d];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@implementation AppController
|
||||
|
@ -55,9 +60,58 @@ extern "C" {
|
|||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
static AppController* appController = NULL;
|
||||
|
||||
|
||||
+ (AppController*) appController
|
||||
{
|
||||
return appController;
|
||||
}
|
||||
|
||||
|
||||
- (void) resetCocos2d
|
||||
{
|
||||
|
||||
UIView* mainView = viewController.view.superview;
|
||||
[viewController.view removeFromSuperview];
|
||||
viewController = nil;
|
||||
cocos2d::CCDirector::sharedDirector()->end();
|
||||
|
||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16 //_OES
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage EAGLView
|
||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
||||
viewController.wantsFullScreenLayout = YES;
|
||||
viewController.view = __glView;
|
||||
|
||||
// Set RootViewController to window
|
||||
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
||||
{
|
||||
// warning: addSubView doesn't work on iOS6
|
||||
[mainView addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[mainView setRootViewController:viewController];
|
||||
}
|
||||
|
||||
// [[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::CCApplication::sharedApplication()->run();
|
||||
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
appController = self;
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
|
@ -93,14 +147,15 @@ static AppDelegate s_sharedApplication;
|
|||
|
||||
cocos2d::CCApplication::sharedApplication()->run();
|
||||
|
||||
|
||||
BOOL isRetina = s_sharedApplication.isRetina;
|
||||
BOOL isIPhone = s_sharedApplication.isIPhone;
|
||||
NSLog(@"ISIphone: %d %d", isIPhone, isRetina);
|
||||
startServer(s_sharedApplication.isRetina, s_sharedApplication.isIPhone);
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotate;
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue