Skip to content

Commit 710c41b

Browse files
add js template
1 parent 1434878 commit 710c41b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5660
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#include "AppDelegate.h"
2+
3+
#include "cocosbuilder/js_bindings_ccbreader.h"
4+
#include "SimpleAudioEngine.h"
5+
#include "jsb_cocos2dx_auto.hpp"
6+
#include "jsb_cocos2dx_extension_auto.hpp"
7+
#include "jsb_cocos2dx_builder_auto.hpp"
8+
#include "extension/jsb_cocos2dx_extension_manual.h"
9+
#include "localstorage/js_bindings_system_registration.h"
10+
#include "chipmunk/js_bindings_chipmunk_registration.h"
11+
#include "jsb_opengl_registration.h"
12+
#include "Runtime.h"
13+
14+
USING_NS_CC;
15+
using namespace CocosDenshion;
16+
17+
AppDelegate::AppDelegate()
18+
{
19+
}
20+
21+
AppDelegate::~AppDelegate()
22+
{
23+
ScriptEngineManager::destroyInstance();
24+
}
25+
26+
bool AppDelegate::applicationDidFinishLaunching()
27+
{
28+
// initialize director
29+
auto director = Director::getInstance();
30+
auto glview = director->getOpenGLView();
31+
if(!glview) {
32+
glview = GLView::createWithRect("HelloJavascript", Rect(0,0,900,640));
33+
director->setOpenGLView(glview);
34+
}
35+
36+
// turn on display FPS
37+
director->setDisplayStats(true);
38+
auto designSize = Size(480, 320);
39+
glview->setDesignResolutionSize(designSize.width, designSize.height, ResolutionPolicy::EXACT_FIT);
40+
// set FPS. the default value is 1.0/60 if you don't call this
41+
director->setAnimationInterval(1.0 / 60);
42+
43+
ScriptingCore* sc = ScriptingCore::getInstance();
44+
sc->addRegisterCallback(register_all_cocos2dx);
45+
sc->addRegisterCallback(register_all_cocos2dx_extension);
46+
sc->addRegisterCallback(register_cocos2dx_js_extensions);
47+
sc->addRegisterCallback(register_all_cocos2dx_extension_manual);
48+
sc->addRegisterCallback(register_all_cocos2dx_builder);
49+
sc->addRegisterCallback(register_CCBuilderReader);
50+
sc->addRegisterCallback(jsb_register_system);
51+
sc->addRegisterCallback(JSB_register_opengl);
52+
sc->addRegisterCallback(jsb_register_chipmunk);
53+
54+
startRuntime();
55+
return true;
56+
}
57+
58+
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
59+
void AppDelegate::applicationDidEnterBackground()
60+
{
61+
Director::getInstance()->stopAnimation();
62+
SimpleAudioEngine::getInstance()->pauseBackgroundMusic();
63+
SimpleAudioEngine::getInstance()->pauseAllEffects();
64+
}
65+
66+
// this function will be called when the app is active again
67+
void AppDelegate::applicationWillEnterForeground()
68+
{
69+
Director::getInstance()->startAnimation();
70+
SimpleAudioEngine::getInstance()->resumeBackgroundMusic();
71+
SimpleAudioEngine::getInstance()->resumeAllEffects();
72+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// GCTestAppDelegate.h
3+
// GCTest
4+
//
5+
// Created by Rohan Kuruvilla on 06/08/2012.
6+
// Copyright __MyCompanyName__ 2012. All rights reserved.
7+
//
8+
9+
#ifndef _APP_DELEGATE_H_
10+
#define _APP_DELEGATE_H_
11+
12+
#include "CCApplication.h"
13+
/**
14+
@brief The cocos2d Application.
15+
16+
The reason for implement as private inheritance is to hide some interface call by Director.
17+
*/
18+
class AppDelegate : private cocos2d::Application
19+
{
20+
public:
21+
AppDelegate();
22+
virtual ~AppDelegate();
23+
24+
/**
25+
@brief Implement Director and Scene init code here.
26+
@return true Initialize success, app continue.
27+
@return false Initialize failed, app terminate.
28+
*/
29+
virtual bool applicationDidFinishLaunching();
30+
31+
/**
32+
@brief The function be called when the application enter background
33+
@param the pointer of the application
34+
*/
35+
virtual void applicationDidEnterBackground();
36+
37+
/**
38+
@brief The function be called when the application enter foreground
39+
@param the pointer of the application
40+
*/
41+
virtual void applicationWillEnterForeground();
42+
};
43+
44+
#endif // _APP_DELEGATE_H_
45+

0 commit comments

Comments
 (0)