Adds lua-hello samples, it works on iOS / Mac .

This commit is contained in:
James Chen 2014-03-11 09:31:16 +08:00
parent c156a1df04
commit f23bb8c9c1
12 changed files with 38 additions and 28 deletions

View File

@ -1 +1 @@
e5d9c2e48fb429281bcc24f65dd8cfafe99b652b d66439c9fcfe71b9c58de2167a4f44a90b311e81

View File

@ -20,14 +20,18 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() { bool AppDelegate::applicationDidFinishLaunching() {
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();
auto glView = EGLView::getInstance(); auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("Hello Cpp");
director->setOpenGLView(glview);
}
director->setOpenGLView(glView); director->setOpenGLView(glview);
// Set the design resolution // Set the design resolution
glView->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER); glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
Size frameSize = glView->getFrameSize(); Size frameSize = glview->getFrameSize();
vector<string> searchPath; vector<string> searchPath;

View File

@ -51,6 +51,6 @@ static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
#endif #endif
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution // The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
#define TITLE_FONT_SIZE (cocos2d::EGLView::getInstance()->getDesignResolutionSize().width / smallResource.size.width * 24) #define TITLE_FONT_SIZE (cocos2d::Director::getInstance()->getOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
#endif /* __APPMACROS_H__ */ #endif /* __APPMACROS_H__ */

View File

@ -1,8 +1,6 @@
#include "HelloWorldScene.h" #include "HelloWorldScene.h"
#include "AppMacros.h" #include "AppMacros.h"
#include "CCEventListenerTouch.h"
USING_NS_CC; USING_NS_CC;
@ -78,7 +76,7 @@ bool HelloWorld::init()
return true; return true;
} }
void HelloWorld::menuCloseCallback(Object* sender) void HelloWorld::menuCloseCallback(Ref* sender)
{ {
Director::getInstance()->end(); Director::getInstance()->end();

View File

@ -13,7 +13,7 @@ public:
static cocos2d::Scene* scene(); static cocos2d::Scene* scene();
// a selector callback // a selector callback
void menuCloseCallback(Object* sender); void menuCloseCallback(Ref* sender);
// implement the "static node()" method manually // implement the "static node()" method manually
CREATE_FUNC(HelloWorld); CREATE_FUNC(HelloWorld);

View File

@ -24,9 +24,8 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "CCEAGLView.h"
#import "RootViewController.h" #import "RootViewController.h"
@implementation AppController @implementation AppController
@ -43,7 +42,7 @@ static AppDelegate s_sharedApplication;
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16 depthFormat: GL_DEPTH_COMPONENT16
preserveBackbuffer: NO preserveBackbuffer: NO
@ -54,7 +53,7 @@ static AppDelegate s_sharedApplication;
// Use RootViewController manage CCEAGLView // Use RootViewController manage CCEAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES; viewController.wantsFullScreenLayout = YES;
viewController.view = __glView; viewController.view = eaglView;
// Set RootViewController to window // Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
@ -72,7 +71,12 @@ static AppDelegate s_sharedApplication;
[[UIApplication sharedApplication] setStatusBarHidden: YES]; [[UIApplication sharedApplication] setStatusBarHidden: YES];
cocos2d::Application::getInstance()->run(); // IMPORTANT: Setting the GLView should be done after creating the RootViewController
cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application *app = cocos2d::Application::getInstance();
app->run();
return YES; return YES;
} }

View File

@ -29,8 +29,6 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("HelloCpp",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }

View File

@ -24,9 +24,15 @@ bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
auto director = Director::getInstance(); auto director = Director::getInstance();
director->setOpenGLView(EGLView::getInstance()); auto glview = director->getOpenGLView();
if(!glview) {
glview = GLView::create("Hello Cpp");
director->setOpenGLView(glview);
}
EGLView::getInstance()->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER); director->setOpenGLView(glview);
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
// turn on display FPS // turn on display FPS
director->setDisplayStats(true); director->setDisplayStats(true);

View File

@ -1,2 +0,0 @@
#Do now ignore Marmalade icf files
!*.icf

View File

@ -1 +0,0 @@
aec1c0a8c8068377fddca5ddd32084d8c3c3c419

View File

@ -24,7 +24,7 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "EAGLView.h" #import "CCEAGLView.h"
#import "AppDelegate.h" #import "AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"
@ -43,7 +43,7 @@ static AppDelegate s_sharedApplication;
// Add the view controller's view to the window and display. // Add the view controller's view to the window and display.
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]]; window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds] CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
pixelFormat: kEAGLColorFormatRGBA8 pixelFormat: kEAGLColorFormatRGBA8
depthFormat: GL_DEPTH_COMPONENT16 depthFormat: GL_DEPTH_COMPONENT16
preserveBackbuffer: NO preserveBackbuffer: NO
@ -54,7 +54,7 @@ static AppDelegate s_sharedApplication;
// Use RootViewController manage CCEAGLView // Use RootViewController manage CCEAGLView
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil]; viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
viewController.wantsFullScreenLayout = YES; viewController.wantsFullScreenLayout = YES;
viewController.view = __glView; viewController.view = eaglView;
// Set RootViewController to window // Set RootViewController to window
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0) if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
@ -72,7 +72,12 @@ static AppDelegate s_sharedApplication;
[[UIApplication sharedApplication] setStatusBarHidden: YES]; [[UIApplication sharedApplication] setStatusBarHidden: YES];
cocos2d::Application::getInstance()->run(); // IMPORTANT: Setting the GLView should be done after creating the RootViewController
cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);
cocos2d::Director::getInstance()->setOpenGLView(glview);
cocos2d::Application *app = cocos2d::Application::getInstance();
app->run();
return YES; return YES;
} }

View File

@ -30,7 +30,5 @@ USING_NS_CC;
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
AppDelegate app; AppDelegate app;
EGLView eglView;
eglView.init("HelloLua",900,640);
return Application::getInstance()->run(); return Application::getInstance()->run();
} }