mirror of https://github.com/axmolengine/axmol.git
removed projects files from old samples folder
This commit is contained in:
parent
5d2f259219
commit
d2b37e05cb
|
@ -1,222 +0,0 @@
|
|||
//
|
||||
// AssetsManagerTestAppDelegate.cpp
|
||||
// AssetsManagerTest
|
||||
//
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
using namespace std;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = EGLView::create("Assets Manager");
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// turn on display FPS
|
||||
//director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
|
||||
|
||||
sc->start();
|
||||
|
||||
auto scene = Scene::create();
|
||||
auto updateLayer = new UpdateLayer();
|
||||
scene->addChild(updateLayer);
|
||||
updateLayer->release();
|
||||
|
||||
director->runWithScene(scene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
||||
}
|
||||
|
||||
UpdateLayer::UpdateLayer()
|
||||
: pItemEnter(NULL)
|
||||
, pItemReset(NULL)
|
||||
, pItemUpdate(NULL)
|
||||
, pProgressLabel(NULL)
|
||||
, isUpdateItemClicked(false)
|
||||
{
|
||||
init();
|
||||
}
|
||||
|
||||
UpdateLayer::~UpdateLayer()
|
||||
{
|
||||
}
|
||||
|
||||
void UpdateLayer::update(cocos2d::Object *pSender)
|
||||
{
|
||||
pProgressLabel->setString("");
|
||||
|
||||
// update resources
|
||||
pAssetsManager->update();
|
||||
|
||||
isUpdateItemClicked = true;
|
||||
}
|
||||
|
||||
void UpdateLayer::reset(cocos2d::Object *pSender)
|
||||
{
|
||||
pProgressLabel->setString(" ");
|
||||
|
||||
// Remove downloaded files
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||
string command = "rm -r ";
|
||||
// Path may include space.
|
||||
command += "\"" + pathToSave + "\"";
|
||||
system(command.c_str());
|
||||
#else
|
||||
string command = "rd /s /q ";
|
||||
// Path may include space.
|
||||
command += "\"" + pathToSave + "\"";
|
||||
system(command.c_str());
|
||||
#endif
|
||||
// Delete recorded version codes.
|
||||
pAssetsManager->deleteVersion();
|
||||
|
||||
createDownloadedDir();
|
||||
}
|
||||
|
||||
void UpdateLayer::enter(cocos2d::Object *pSender)
|
||||
{
|
||||
// Should set search resource path before running script if "update" is not clicked.
|
||||
// Because AssetsManager will set
|
||||
if (! isUpdateItemClicked)
|
||||
{
|
||||
vector<string> searchPaths = FileUtils::getInstance()->getSearchPaths();
|
||||
searchPaths.insert(searchPaths.begin(), pathToSave);
|
||||
FileUtils::getInstance()->setSearchPaths(searchPaths);
|
||||
}
|
||||
|
||||
auto pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("main.js");
|
||||
}
|
||||
|
||||
bool UpdateLayer::init()
|
||||
{
|
||||
Layer::init();
|
||||
|
||||
createDownloadedDir();
|
||||
|
||||
/** Creates assets manager */
|
||||
pAssetsManager = new AssetsManager("https://raw.github.com/minggo/AssetsManagerTest/master/package.zip",
|
||||
"https://raw.github.com/minggo/AssetsManagerTest/master/version",
|
||||
pathToSave.c_str());
|
||||
pAssetsManager->setDelegate(this);
|
||||
pAssetsManager->setConnectionTimeout(3);
|
||||
addChild(pAssetsManager);
|
||||
pAssetsManager->release();
|
||||
|
||||
auto size = Director::getInstance()->getWinSize();
|
||||
|
||||
pItemReset = MenuItemFont::create("reset", CC_CALLBACK_1(UpdateLayer::reset,this));
|
||||
pItemEnter = MenuItemFont::create("enter", CC_CALLBACK_1(UpdateLayer::enter, this));
|
||||
pItemUpdate = MenuItemFont::create("update", CC_CALLBACK_1(UpdateLayer::update, this));
|
||||
|
||||
pItemEnter->setPosition(Point(size.width/2, size.height/2 + 50));
|
||||
pItemReset->setPosition(Point(size.width/2, size.height/2));
|
||||
pItemUpdate->setPosition(Point(size.width/2, size.height/2 - 50));
|
||||
|
||||
auto menu = Menu::create(pItemUpdate, pItemEnter, pItemReset, NULL);
|
||||
menu->setPosition(Point(0,0));
|
||||
addChild(menu);
|
||||
|
||||
pProgressLabel = LabelTTF::create("", "Arial", 20);
|
||||
pProgressLabel->setPosition(Point(100, 50));
|
||||
addChild(pProgressLabel);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void UpdateLayer::createDownloadedDir()
|
||||
{
|
||||
pathToSave = FileUtils::getInstance()->getWritablePath();
|
||||
pathToSave += "tmpdir";
|
||||
|
||||
// Create the folder if it doesn't exist
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WIN32)
|
||||
DIR *pDir = NULL;
|
||||
|
||||
pDir = opendir (pathToSave.c_str());
|
||||
if (! pDir)
|
||||
{
|
||||
mkdir(pathToSave.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
|
||||
}
|
||||
#else
|
||||
if ((GetFileAttributesA(pathToSave.c_str())) == INVALID_FILE_ATTRIBUTES)
|
||||
{
|
||||
CreateDirectoryA(pathToSave.c_str(), 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void UpdateLayer::onError(AssetsManager::ErrorCode errorCode)
|
||||
{
|
||||
if (errorCode == AssetsManager::ErrorCode::NO_NEW_VERSION)
|
||||
{
|
||||
pProgressLabel->setString("no new version");
|
||||
}
|
||||
|
||||
if (errorCode == AssetsManager::ErrorCode::NETWORK)
|
||||
{
|
||||
pProgressLabel->setString("network error");
|
||||
}
|
||||
}
|
||||
|
||||
void UpdateLayer::onProgress(int percent)
|
||||
{
|
||||
char progress[20];
|
||||
snprintf(progress, 20, "downloading %d%%", percent);
|
||||
pProgressLabel->setString(progress);
|
||||
}
|
||||
|
||||
void UpdateLayer::onSuccess()
|
||||
{
|
||||
pProgressLabel->setString("download ok");
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "HelloWorldScene.h"
|
||||
#include "AppMacros.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace std;
|
||||
|
||||
AppDelegate::AppDelegate() {
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("Hello Cpp", Size(480, 720));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
// Set the design resolution
|
||||
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
Size frameSize = glview->getFrameSize();
|
||||
|
||||
vector<string> searchPath;
|
||||
|
||||
// In this demo, we select resource according to the frame's height.
|
||||
// If the resource size is different from design resolution size, you need to set contentScaleFactor.
|
||||
// We use the ratio of resource's height to the height of design resolution,
|
||||
// this can make sure that the resource's height could fit for the height of design resolution.
|
||||
|
||||
// if the frame's height is larger than the height of medium resource size, select large resource.
|
||||
if (frameSize.height > mediumResource.size.height)
|
||||
{
|
||||
searchPath.push_back(largeResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
// if the frame's height is larger than the height of small resource size, select medium resource.
|
||||
else if (frameSize.height > smallResource.size.height)
|
||||
{
|
||||
searchPath.push_back(mediumResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
// if the frame's height is smaller than the height of medium resource size, select small resource.
|
||||
else
|
||||
{
|
||||
searchPath.push_back(smallResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
|
||||
// set searching path
|
||||
FileUtils::getInstance()->setSearchPaths(searchPath);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
auto scene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
director->runWithScene(scene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground() {
|
||||
Director::getInstance()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground() {
|
||||
Director::getInstance()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
#ifndef __APPMACROS_H__
|
||||
#define __APPMACROS_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
/* For demonstrating using one design resolution to match different resources,
|
||||
or one resource to match different design resolutions.
|
||||
|
||||
[Situation 1] Using one design resolution to match different resources.
|
||||
Please look into Appdelegate::applicationDidFinishLaunching.
|
||||
We check current device frame size to decide which resource need to be selected.
|
||||
So if you want to test this situation which said in title '[Situation 1]',
|
||||
you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
|
||||
or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
|
||||
and modify "proj.mac/AppController.mm" by changing the window rectangle.
|
||||
|
||||
[Situation 2] Using one resource to match different design resolutions.
|
||||
The coordinates in your codes is based on your current design resolution rather than resource size.
|
||||
Therefore, your design resolution could be very large and your resource size could be small.
|
||||
To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
|
||||
and open iphone simulator or create a window of 480x320 size.
|
||||
|
||||
[Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
|
||||
*/
|
||||
|
||||
#define DESIGN_RESOLUTION_480X320 0
|
||||
#define DESIGN_RESOLUTION_1024X768 1
|
||||
#define DESIGN_RESOLUTION_2048X1536 2
|
||||
|
||||
/* If you want to switch design resolution, change next line */
|
||||
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320
|
||||
|
||||
typedef struct tagResource
|
||||
{
|
||||
cocos2d::Size size;
|
||||
char directory[100];
|
||||
}Resource;
|
||||
|
||||
static Resource smallResource = { cocos2d::Size(480, 320), "iphone" };
|
||||
static Resource mediumResource = { cocos2d::Size(1024, 768), "ipad" };
|
||||
static Resource largeResource = { cocos2d::Size(2048, 1536), "ipadhd" };
|
||||
|
||||
#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
|
||||
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(1024, 768);
|
||||
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
|
||||
#else
|
||||
#error unknown target design resolution!
|
||||
#endif
|
||||
|
||||
// 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::Director::getInstance()->getOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
|
||||
|
||||
#endif /* __APPMACROS_H__ */
|
|
@ -1,134 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup:nil
|
||||
multiSampling:NO
|
||||
numberOfSamples:0];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "HelloWorldScene.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
|
||||
AppDelegate::AppDelegate() {
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
glview = EGLView::createWithSize("Simple Game", Size(900,640));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
auto screenSize = glview->getFrameSize();
|
||||
auto designSize = Size(480, 320);
|
||||
std::vector<std::string> searchPaths;
|
||||
|
||||
if (screenSize.height > 320)
|
||||
{
|
||||
searchPaths.push_back("hd");
|
||||
searchPaths.push_back("sd");
|
||||
director->setContentScaleFactor(640.0f/designSize.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
searchPaths.push_back("sd");
|
||||
director->setContentScaleFactor(320.0f/designSize.height);
|
||||
}
|
||||
|
||||
FileUtils::getInstance()->setSearchPaths(searchPaths);
|
||||
|
||||
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
auto scene = HelloWorld::scene();
|
||||
|
||||
// run
|
||||
director->runWithScene(scene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground() {
|
||||
Director::getInstance()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// CocosDenshion::SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground() {
|
||||
Director::getInstance()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// CocosDenshion::SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup:nil
|
||||
multiSampling:NO
|
||||
numberOfSamples:0];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching() override;
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground() override;
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground() override;
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_builder_auto.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "cocosbuilder/js_bindings_ccbreader.h"
|
||||
#include "localstorage/js_bindings_system_registration.h"
|
||||
#include "chipmunk/js_bindings_chipmunk_registration.h"
|
||||
#include "jsb_opengl_registration.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
using namespace std;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
ScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("CocosDragon JS", Size(480, 720));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(320, 480);
|
||||
auto resourceSize = Size(320, 480);
|
||||
|
||||
std::vector<std::string> resDirOrders;
|
||||
|
||||
Platform platform = Application::getInstance()->getTargetPlatform();
|
||||
if (platform == Application::Platform::OS_IPHONE || platform == Application::Platform::OS_IPAD || platform == Application::Platform::OS_MAC)
|
||||
{
|
||||
std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths();
|
||||
searchPaths.insert(searchPaths.begin(), "Published files iOS");
|
||||
FileUtils::getInstance()->setSearchPaths(searchPaths);
|
||||
if (screenSize.height > 1024)
|
||||
{
|
||||
resourceSize = Size(1536, 2048);
|
||||
resDirOrders.push_back("resources-ipadhd");
|
||||
resDirOrders.push_back("resources-ipad");
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
}
|
||||
else if (screenSize.height > 960)
|
||||
{
|
||||
resourceSize = Size(768, 1024);
|
||||
resDirOrders.push_back("resources-ipad");
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
}
|
||||
else if (screenSize.height > 480)
|
||||
{
|
||||
resourceSize = Size(640, 960);
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceSize = Size(320, 480);
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
}
|
||||
|
||||
}
|
||||
else if (platform == Application::Platform::OS_ANDROID || platform == Application::Platform::OS_WINDOWS)
|
||||
{
|
||||
if (screenSize.height > 960)
|
||||
{
|
||||
resourceSize = Size(1280, 1920);
|
||||
resDirOrders.push_back("resources-xlarge");
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else if (screenSize.height > 720)
|
||||
{
|
||||
resourceSize = Size(640, 960);
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else if (screenSize.height > 480)
|
||||
{
|
||||
resourceSize = Size(480, 720);
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceSize = Size(320, 480);
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
}
|
||||
|
||||
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
|
||||
|
||||
director->setContentScaleFactor(resourceSize.width/designSize.width);
|
||||
|
||||
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_builder);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
|
||||
sc->start();
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
sc->enableDebugger();
|
||||
#endif
|
||||
|
||||
js_log("RUNNING Main");
|
||||
auto pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("main.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// testjsAppController.mm
|
||||
// testjs
|
||||
//
|
||||
// Created by Rolando Abarca on 3/19/12.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16 //_OES
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->purgeCachedData();
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
|
@ -1,148 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_builder_auto.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "cocosbuilder/js_bindings_ccbreader.h"
|
||||
#include "localstorage/js_bindings_system_registration.h"
|
||||
#include "chipmunk/js_bindings_chipmunk_registration.h"
|
||||
#include "jsb_opengl_registration.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
ScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("Crystal Craze", Size(480, 720));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
auto screenSize = glview->getFrameSize();
|
||||
|
||||
auto designSize = Size(320, 480);
|
||||
auto resourceSize = Size(320, 480);
|
||||
|
||||
std::vector<std::string> searchPaths = FileUtils::getInstance()->getSearchPaths();
|
||||
std::vector<std::string> resDirOrders;
|
||||
|
||||
Application::Platform platform = Application::getInstance()->getTargetPlatform();
|
||||
if (platform == Application::Platform::OS_IPHONE || platform == Application::Platform::OS_IPAD || platform == Application::Platform::OS_MAC)
|
||||
{
|
||||
searchPaths.push_back("Published-iOS"); // Resources/Published-iOS
|
||||
FileUtils::getInstance()->setSearchPaths(searchPaths);
|
||||
|
||||
if (screenSize.height > 480)
|
||||
{
|
||||
resourceSize = Size(640, 960);
|
||||
resDirOrders.push_back("resources-iphonehd");
|
||||
}
|
||||
else
|
||||
{
|
||||
resDirOrders.push_back("resources-iphone");
|
||||
}
|
||||
|
||||
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
|
||||
}
|
||||
else if (platform == Application::Platform::OS_ANDROID || platform == Application::Platform::OS_WINDOWS)
|
||||
{
|
||||
// Comments it since opengles2.0 only supports texture size within 2048x2048.
|
||||
// if (screenSize.height > 1024)
|
||||
// {
|
||||
// resourceSize = Size(1280, 1920);
|
||||
// resDirOrders.push_back("resources-xlarge");
|
||||
// resDirOrders.push_back("");
|
||||
// }
|
||||
// else
|
||||
if (screenSize.height > 960)
|
||||
{
|
||||
resourceSize = Size(640, 960);
|
||||
resDirOrders.push_back("resources-large");
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else if (screenSize.height > 480)
|
||||
{
|
||||
resourceSize = Size(480, 720);
|
||||
resDirOrders.push_back("resources-medium");
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
else
|
||||
{
|
||||
resourceSize = Size(320, 568);
|
||||
resDirOrders.push_back("resources-small");
|
||||
}
|
||||
|
||||
FileUtils::getInstance()->setSearchResolutionsOrder(resDirOrders);
|
||||
}
|
||||
director->setContentScaleFactor(resourceSize.width/designSize.width);
|
||||
|
||||
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::SHOW_ALL);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_builder);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
|
||||
sc->start();
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
sc->enableDebugger();
|
||||
#endif
|
||||
|
||||
js_log("RUNNING Main");
|
||||
auto pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("main.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// testjsAppController.mm
|
||||
// testjs
|
||||
//
|
||||
// Created by Rolando Abarca on 3/19/12.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16 //_OES
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->purgeCachedData();
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
|
@ -1,90 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_builder_auto.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "cocosbuilder/js_bindings_ccbreader.h"
|
||||
#include "localstorage/js_bindings_system_registration.h"
|
||||
#include "chipmunk/js_bindings_chipmunk_registration.h"
|
||||
#include "jsb_opengl_registration.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
ScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("Moon Warriors", Size(480, 720));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
director->setProjection(Director::Projection::_2D);
|
||||
|
||||
// Set the design resolution
|
||||
glview->setDesignResolutionSize(320, 480, ResolutionPolicy::SHOW_ALL);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_builder);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
|
||||
sc->start();
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
sc->enableDebugger();
|
||||
#endif
|
||||
|
||||
auto pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
|
||||
ScriptingCore::getInstance()->runScript("MoonWarriors-jsb.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// testjsAppController.mm
|
||||
// testjs
|
||||
//
|
||||
// Created by Rolando Abarca on 3/19/12.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16 //_OES
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->purgeCachedData();
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
@ -1,86 +0,0 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "ScriptingCore.h"
|
||||
#include "jsb_cocos2dx_auto.hpp"
|
||||
#include "jsb_cocos2dx_extension_auto.hpp"
|
||||
#include "jsb_cocos2dx_builder_auto.hpp"
|
||||
#include "extension/jsb_cocos2dx_extension_manual.h"
|
||||
#include "cocos2d_specifics.hpp"
|
||||
#include "chipmunk/js_bindings_chipmunk_registration.h"
|
||||
#include "cocosbuilder/js_bindings_ccbreader.h"
|
||||
#include "localstorage/js_bindings_system_registration.h"
|
||||
#include "jsb_opengl_registration.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
ScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("Watermelon With Me", Size(900,640));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::FIXED_HEIGHT);
|
||||
|
||||
FileUtils::getInstance()->addSearchPath("script");
|
||||
|
||||
ScriptingCore* sc = ScriptingCore::getInstance();
|
||||
sc->addRegisterCallback(register_all_cocos2dx);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
|
||||
sc->addRegisterCallback(register_cocos2dx_js_extensions);
|
||||
sc->addRegisterCallback(jsb_register_chipmunk);
|
||||
sc->addRegisterCallback(register_all_cocos2dx_builder);
|
||||
sc->addRegisterCallback(register_CCBuilderReader);
|
||||
sc->addRegisterCallback(jsb_register_system);
|
||||
sc->addRegisterCallback(JSB_register_opengl);
|
||||
|
||||
sc->start();
|
||||
|
||||
#if defined(COCOS2D_DEBUG) && (COCOS2D_DEBUG > 0)
|
||||
sc->enableDebugger();
|
||||
#endif
|
||||
|
||||
auto pEngine = ScriptingCore::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(pEngine);
|
||||
ScriptingCore::getInstance()->runScript("boot-jsb.js");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->pauseAllEffects();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
SimpleAudioEngine::getInstance()->resumeAllEffects();
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
//
|
||||
// testjsAppController.mm
|
||||
// testjs
|
||||
//
|
||||
// Created by Rolando Abarca on 3/19/12.
|
||||
// Copyright __MyCompanyName__ 2012. All rights reserved.
|
||||
//
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16 //_OES
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->purgeCachedData();
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
#include "cocos2d.h"
|
||||
#include "AppDelegate.h"
|
||||
#include "SimpleAudioEngine.h"
|
||||
#include "CCScriptSupport.h"
|
||||
#include "CCLuaEngine.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
{
|
||||
// fixed me
|
||||
//_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF|_CRTDBG_LEAK_CHECK_DF);
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
// end simple audio engine here, or it may crashed on win32
|
||||
SimpleAudioEngine::getInstance()->end();
|
||||
//CCScriptEngineManager::destroyInstance();
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching()
|
||||
{
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
auto glview = EGLView::createWithSize("Hello Lua", Size(900,640));
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
glview->setDesignResolutionSize(480, 320, ResolutionPolicy::NO_BORDER);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// register lua engine
|
||||
LuaEngine* engine = LuaEngine::getInstance();
|
||||
ScriptEngineManager::getInstance()->setScriptEngine(engine);
|
||||
|
||||
//The call was commented because it will lead to ZeroBrane Studio can't find correct context when debugging
|
||||
//engine->executeScriptFile("hello.lua");
|
||||
engine->executeString("require 'hello.lua'");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground()
|
||||
{
|
||||
Director::getInstance()->stopAnimation();
|
||||
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground()
|
||||
{
|
||||
Director::getInstance()->startAnimation();
|
||||
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
|
||||
}
|
|
@ -1,134 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *__glView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
numberOfSamples: 0 ];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
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
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
cocos2d::Application::getInstance()->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#include "AppDelegate.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
AppDelegate app;
|
||||
return Application::getInstance()->run();
|
||||
}
|
Loading…
Reference in New Issue