├── .project
├── HelloWorld
├── .project
├── Classes
│ ├── AppDelegate.cpp
│ ├── AppDelegate.h
│ ├── HelloWorldScene.cpp
│ └── HelloWorldScene.h
├── README.md
├── Resources
│ ├── CloseNormal.png
│ ├── CloseSelected.png
│ └── HelloWorld.png
├── proj.android
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── build.xml
│ ├── build_native.sh
│ ├── jni
│ │ ├── Android.mk
│ │ ├── Application.mk
│ │ ├── hellocpp
│ │ │ └── main.cpp
│ │ └── list.sh
│ ├── local.properties
│ ├── ndkgdb.sh
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── icon.png
│ │ ├── drawable-ldpi
│ │ │ └── icon.png
│ │ ├── drawable-mdpi
│ │ │ └── icon.png
│ │ └── values
│ │ │ └── strings.xml
│ └── src
│ │ └── com
│ │ └── leafsoar
│ │ └── game
│ │ └── HelloWorld.java
└── proj.linux
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── Makefile
│ ├── main.cpp
│ └── main.h
├── Learn
├── Classes
│ ├── AppDelegate.cpp
│ ├── AppDelegate.h
│ ├── CustomeControl
│ │ ├── CustomeControlTest.cpp
│ │ └── CustomeControlTest.h
│ ├── GlobalSchedule
│ │ ├── GlobalSchedule.cpp
│ │ └── GlobalSchedule.h
│ ├── LSLog.cpp
│ ├── LSLog.h
│ ├── Property
│ │ ├── Property.cpp
│ │ └── Property.h
│ ├── TouchEventTest
│ │ ├── LsTouch.cpp
│ │ ├── LsTouch.h
│ │ ├── TouchEventTest.cpp
│ │ └── TouchEventTest.h
│ ├── TouchScaleTest
│ │ ├── TouchScaleTest.cpp
│ │ └── TouchScaleTest.h
│ ├── VisibleRect.cpp
│ ├── VisibleRect.h
│ ├── controller.cpp
│ ├── controller.h
│ ├── testBasic.cpp
│ ├── testBasic.h
│ ├── testResource.h
│ └── tests.h
├── README.md
├── proj.android
│ ├── .classpath
│ ├── .gitignore
│ ├── .project
│ ├── AndroidManifest.xml
│ ├── ant.properties
│ ├── build.xml
│ ├── build_native.sh
│ ├── jni
│ │ ├── Android.mk
│ │ ├── Application.mk
│ │ ├── hellocpp
│ │ │ └── main.cpp
│ │ └── list.sh
│ ├── local.properties
│ ├── ndkgdb.sh
│ ├── proguard-project.txt
│ ├── project.properties
│ ├── res
│ │ ├── drawable-hdpi
│ │ │ └── icon.png
│ │ ├── drawable-ldpi
│ │ │ └── icon.png
│ │ ├── drawable-mdpi
│ │ │ └── icon.png
│ │ └── values
│ │ │ └── strings.xml
│ └── src
│ │ └── com
│ │ └── leafsoar
│ │ └── game
│ │ └── learn
│ │ └── HelloWorld.java
└── proj.linux
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── Makefile
│ ├── main.cpp
│ └── main.h
├── Libs
├── README.md
└── rapidjson
│ └── include
│ └── rapidjson
│ ├── document.h
│ ├── filestream.h
│ ├── internal
│ ├── pow10.h
│ ├── stack.h
│ └── strfunc.h
│ ├── prettywriter.h
│ ├── rapidjson.h
│ ├── reader.h
│ ├── stringbuffer.h
│ └── writer.h
├── MacCpp
├── .cproject
├── .externalToolBuilders
│ └── Javah_jni_builder.launch
├── Classes
│ ├── AppDelegate.cpp
│ ├── AppDelegate.h
│ ├── HelloWorldScene.cpp
│ ├── HelloWorldScene.h
│ ├── LevelView.cpp
│ ├── LevelView.h
│ ├── LsTouch.cpp
│ ├── LsTouch.h
│ └── PopupLayer
│ │ ├── PopupLayer.cpp
│ │ ├── PopupLayer.h
│ │ ├── PopupScene.cpp
│ │ └── PopupScene.h
├── Resources
│ ├── .gitignore
│ ├── CloseNormal.png
│ ├── CloseSelected.png
│ ├── CocosBuilderExample.ccbproj
│ ├── CocosBuilderExample.ccbresourcelog
│ ├── Default.png
│ ├── HelloWorld.png
│ ├── app.icf
│ ├── development.icf
│ ├── fileLookup.plist
│ ├── level
│ │ ├── GameBackGround.png
│ │ ├── ball.png
│ │ ├── frame.png
│ │ ├── level.png
│ │ ├── level_lock.png
│ │ ├── prim30.fnt
│ │ ├── prim30.png
│ │ ├── sel.png
│ │ ├── star5.png
│ │ └── star6.png
│ └── popuplayer
│ │ ├── BackGround.png
│ │ └── pop_button.png
└── proj.mac
│ ├── AppController.h
│ ├── AppController.mm
│ ├── Icon.icns
│ ├── TestCpp.xcodeproj
│ ├── project.pbxproj
│ ├── project.xcworkspace
│ │ ├── contents.xcworkspacedata
│ │ └── xcuserdata
│ │ │ └── leafsoar.xcuserdatad
│ │ │ └── UserInterfaceState.xcuserstate
│ └── xcuserdata
│ │ └── leafsoar.xcuserdatad
│ │ └── xcschemes
│ │ ├── TestCpp.xcscheme
│ │ └── xcschememanagement.plist
│ ├── Test_Info.plist
│ ├── Test_Prefix.pch
│ ├── en.lproj
│ ├── InfoPlist.strings
│ └── MainMenu.xib
│ └── main.m
├── README.md
├── Resources
├── Peas.png
├── close.png
└── move.jpg
├── ScreenSolutions
├── Classes
│ ├── AppDelegate.cpp
│ ├── AppDelegate.h
│ ├── HelloWorldScene.cpp
│ └── HelloWorldScene.h
├── README.md
├── Resources
│ ├── Back.jpg
│ ├── CloseNormal.png
│ ├── CloseSelected.png
│ ├── HelloWorld.png
│ ├── Peas.png
│ └── fonts
│ │ ├── prim36.fnt
│ │ └── prim36.png
└── proj.linux
│ ├── .cproject
│ ├── .gitignore
│ ├── .project
│ ├── Makefile
│ ├── main.cpp
│ └── main.h
└── Third
├── Classes
├── AppDelegate.cpp
├── AppDelegate.h
├── HelloWorldScene.cpp
└── HelloWorldScene.h
├── README.md
└── proj.linux
├── .cproject
├── .gitignore
├── .project
├── Makefile
├── main.cpp
└── main.h
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ls-cocos2d-x
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/HelloWorld/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloWorld
4 |
5 |
6 | HelloWorld_dx
7 | HelloWorld_j
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/HelloWorld/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 |
3 | #include "cocos2d.h"
4 | #include "HelloWorldScene.h"
5 |
6 | USING_NS_CC;
7 |
8 | AppDelegate::AppDelegate()
9 | {
10 |
11 | }
12 |
13 | AppDelegate::~AppDelegate()
14 | {
15 | }
16 |
17 | bool AppDelegate::applicationDidFinishLaunching()
18 | {
19 | // initialize director
20 | CCDirector *pDirector = CCDirector::sharedDirector();
21 | pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
22 |
23 | // turn on display FPS
24 | pDirector->setDisplayStats(true);
25 |
26 | // set FPS. the default value is 1.0/60 if you don't call this
27 | pDirector->setAnimationInterval(1.0 / 60);
28 |
29 | // create a scene. it's an autorelease object
30 | CCScene *pScene = HelloWorld::scene();
31 |
32 | // run
33 | pDirector->runWithScene(pScene);
34 |
35 | return true;
36 | }
37 |
38 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
39 | void AppDelegate::applicationDidEnterBackground()
40 | {
41 | CCDirector::sharedDirector()->pause();
42 |
43 | // if you use SimpleAudioEngine, it must be pause
44 | // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
45 | }
46 |
47 | // this function will be called when the app is active again
48 | void AppDelegate::applicationWillEnterForeground()
49 | {
50 | CCDirector::sharedDirector()->resume();
51 |
52 | // if you use SimpleAudioEngine, it must resume here
53 | // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
54 | }
55 |
--------------------------------------------------------------------------------
/HelloWorld/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "CCApplication.h"
5 |
6 | /**
7 | @brief The cocos2d Application.
8 |
9 | The reason for implement as private inheritance is to hide some interface call by CCDirector.
10 | */
11 | class AppDelegate : private cocos2d::CCApplication
12 | {
13 | public:
14 | AppDelegate();
15 | virtual ~AppDelegate();
16 |
17 | /**
18 | @brief Implement CCDirector and CCScene init code here.
19 | @return true Initialize success, app continue.
20 | @return false Initialize failed, app terminate.
21 | */
22 | virtual bool applicationDidFinishLaunching();
23 |
24 | /**
25 | @brief The function be called when the application enter background
26 | @param the pointer of the application
27 | */
28 | virtual void applicationDidEnterBackground();
29 |
30 | /**
31 | @brief The function be called when the application enter foreground
32 | @param the pointer of the application
33 | */
34 | virtual void applicationWillEnterForeground();
35 | };
36 |
37 | #endif // _APP_DELEGATE_H_
38 |
39 |
--------------------------------------------------------------------------------
/HelloWorld/Classes/HelloWorldScene.cpp:
--------------------------------------------------------------------------------
1 | #include "HelloWorldScene.h"
2 | #include "SimpleAudioEngine.h"
3 |
4 | using namespace cocos2d;
5 | using namespace CocosDenshion;
6 |
7 | CCScene* HelloWorld::scene()
8 | {
9 | // 'scene' is an autorelease object
10 | CCScene *scene = CCScene::create();
11 |
12 | // 'layer' is an autorelease object
13 | HelloWorld *layer = HelloWorld::create();
14 |
15 | // add layer as a child to scene
16 | scene->addChild(layer);
17 |
18 | // return the scene
19 | return scene;
20 | }
21 |
22 | // on "init" you need to initialize your instance
23 | bool HelloWorld::init()
24 | {
25 | //////////////////////////////
26 | // 1. super init first
27 | if ( !CCLayer::init() )
28 | {
29 | return false;
30 | }
31 |
32 | /////////////////////////////
33 | // 2. add a menu item with "X" image, which is clicked to quit the program
34 | // you may modify it.
35 |
36 | // add a "close" icon to exit the progress. it's an autorelease object
37 | CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
38 | "CloseNormal.png",
39 | "CloseSelected.png",
40 | this,
41 | menu_selector(HelloWorld::menuCloseCallback) );
42 | pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
43 |
44 | // create menu, it's an autorelease object
45 | CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
46 | pMenu->setPosition( CCPointZero );
47 | this->addChild(pMenu, 1);
48 |
49 | /////////////////////////////
50 | // 3. add your codes below...
51 |
52 | // add a label shows "Hello World"
53 | // create and initialize a label
54 | CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
55 |
56 | // ask director the window size
57 | CCSize size = CCDirector::sharedDirector()->getWinSize();
58 |
59 | // position the label on the center of the screen
60 | pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
61 |
62 | // add the label as a child to this layer
63 | this->addChild(pLabel, 1);
64 |
65 | // add "HelloWorld" splash screen"
66 | CCSprite* pSprite = CCSprite::create("HelloWorld.png");
67 |
68 | // position the sprite on the center of the screen
69 | pSprite->setPosition( ccp(size.width/2, size.height/2) );
70 |
71 | // add the sprite as a child to this layer
72 | this->addChild(pSprite, 0);
73 |
74 | return true;
75 | }
76 |
77 | void HelloWorld::menuCloseCallback(CCObject* pSender)
78 | {
79 | CCDirector::sharedDirector()->end();
80 |
81 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
82 | exit(0);
83 | #endif
84 | }
85 |
--------------------------------------------------------------------------------
/HelloWorld/Classes/HelloWorldScene.h:
--------------------------------------------------------------------------------
1 | #ifndef __HELLOWORLD_SCENE_H__
2 | #define __HELLOWORLD_SCENE_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | class HelloWorld : public cocos2d::CCLayer
7 | {
8 | public:
9 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
10 | virtual bool init();
11 |
12 | // there's no 'id' in cpp, so we recommand to return the exactly class pointer
13 | static cocos2d::CCScene* scene();
14 |
15 | // a selector callback
16 | void menuCloseCallback(CCObject* pSender);
17 |
18 | // implement the "static node()" method manually
19 | CREATE_FUNC(HelloWorld);
20 | };
21 |
22 | #endif // __HELLOWORLD_SCENE_H__
23 |
--------------------------------------------------------------------------------
/HelloWorld/README.md:
--------------------------------------------------------------------------------
1 | # leafsoar 的代码示例
2 |
3 | 源代码路径: ./Classes
4 |
5 | 资源文件路径: ./Resources
6 |
7 | 详情请见博文
8 |
9 | Eclipse 组织跨平台开发 Cocos2d-x 游戏
10 |
11 | Eclipse Cocos2d-x 开发自动管理
12 |
--------------------------------------------------------------------------------
/HelloWorld/Resources/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/Resources/CloseNormal.png
--------------------------------------------------------------------------------
/HelloWorld/Resources/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/Resources/CloseSelected.png
--------------------------------------------------------------------------------
/HelloWorld/Resources/HelloWorld.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/Resources/HelloWorld.png
--------------------------------------------------------------------------------
/HelloWorld/proj.android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/.gitignore:
--------------------------------------------------------------------------------
1 | /gen
2 | /assets
3 | /bin
4 | /libs
5 | /obj
6 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloWorld_j
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
49 |
50 |
51 |
52 |
56 |
57 |
69 |
70 |
71 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/build_native.sh:
--------------------------------------------------------------------------------
1 | APPNAME="HelloWorld"
2 |
3 | # options
4 |
5 | buildexternalsfromsource=
6 |
7 | usage(){
8 | cat << EOF
9 | usage: $0 [options]
10 |
11 | Build C/C++ code for $APPNAME using Android NDK
12 |
13 | OPTIONS:
14 | -s Build externals from source
15 | -h this help
16 | EOF
17 | }
18 |
19 | while getopts "sh" OPTION; do
20 | case "$OPTION" in
21 | s)
22 | buildexternalsfromsource=1
23 | ;;
24 | h)
25 | usage
26 | exit 0
27 | ;;
28 | esac
29 | done
30 |
31 | # paths
32 |
33 | if [ -z "${NDK_ROOT+aaa}" ];then
34 | echo "please define NDK_ROOT"
35 | exit 1
36 | fi
37 |
38 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
39 | # ... use paths relative to current directory
40 | COCOS2DX_ROOT="/home/leafsoar/Tools/android/cocos2d-x/cocos2d-2.0-x-2.0.4"
41 | APP_ROOT="$DIR/.."
42 | APP_ANDROID_ROOT="$DIR"
43 |
44 | echo "NDK_ROOT = $NDK_ROOT"
45 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
46 | echo "APP_ROOT = $APP_ROOT"
47 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
48 |
49 | # make sure assets is exist
50 | if [ -d "$APP_ANDROID_ROOT"/assets ]; then
51 | rm -rf "$APP_ANDROID_ROOT"/assets
52 | fi
53 |
54 | mkdir "$APP_ANDROID_ROOT"/assets
55 |
56 | # copy resources
57 | for file in "$APP_ROOT"/Resources/*
58 | do
59 | if [ -d "$file" ]; then
60 | cp -rf "$file" "$APP_ANDROID_ROOT"/assets
61 | fi
62 |
63 | if [ -f "$file" ]; then
64 | cp "$file" "$APP_ANDROID_ROOT"/assets
65 | fi
66 | done
67 |
68 | # copy icons (if they exist)
69 | file="$APP_ANDROID_ROOT"/assets/Icon-72.png
70 | if [ -f "$file" ]; then
71 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
72 | fi
73 | file="$APP_ANDROID_ROOT"/assets/Icon-48.png
74 | if [ -f "$file" ]; then
75 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
76 | fi
77 | file="$APP_ANDROID_ROOT"/assets/Icon-32.png
78 | if [ -f "$file" ]; then
79 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
80 | fi
81 |
82 |
83 | if [[ "$buildexternalsfromsource" ]]; then
84 | echo "Building external dependencies from source"
85 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
86 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
87 | else
88 | echo "Using prebuilt externals"
89 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
90 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
91 | fi
92 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := game_shared
6 |
7 | LOCAL_MODULE_FILENAME := libgame
8 |
9 | define all-cpp-files
10 | $(patsubst jni/%,%, $(shell find $(LOCAL_PATH)/../../Classes/ $(LOCAL_PATH)/hellocpp -name "*.cpp"))
11 | endef
12 |
13 | LOCAL_SRC_FILES := $(call all-cpp-files)
14 |
15 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
16 |
17 | LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
18 |
19 | include $(BUILD_SHARED_LIBRARY)
20 |
21 | $(call import-module,CocosDenshion/android) \
22 | $(call import-module,cocos2dx) \
23 | $(call import-module,extensions)
24 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
2 | APP_CPPFLAGS := -frtti
--------------------------------------------------------------------------------
/HelloWorld/proj.android/jni/hellocpp/main.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 | #include "platform/android/jni/JniHelper.h"
3 | #include
4 | #include
5 |
6 | #include "HelloWorldScene.h"
7 |
8 | #define LOG_TAG "main"
9 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
10 |
11 | using namespace cocos2d;
12 |
13 | extern "C"
14 | {
15 |
16 | jint JNI_OnLoad(JavaVM *vm, void *reserved)
17 | {
18 | JniHelper::setJavaVM(vm);
19 |
20 | return JNI_VERSION_1_4;
21 | }
22 |
23 | void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
24 | {
25 | if (!CCDirector::sharedDirector()->getOpenGLView())
26 | {
27 | CCEGLView *view = CCEGLView::sharedOpenGLView();
28 | view->setFrameSize(w, h);
29 |
30 | AppDelegate *pAppDelegate = new AppDelegate();
31 | CCApplication::sharedApplication()->run();
32 | }
33 | else
34 | {
35 | ccDrawInit();
36 | ccGLInvalidateStateCache();
37 |
38 | CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
39 | CCTextureCache::reloadAllTextures();
40 | CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
41 | CCDirector::sharedDirector()->setGLDefaultValues();
42 | }
43 | }
44 |
45 | }
46 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/jni/list.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | append_str=' \'
4 |
5 | list_alldir()
6 | {
7 | for file in $1/*
8 | do
9 | if [ -f $file ]; then
10 | echo $file$append_str | grep .cpp
11 | fi
12 |
13 | if [ -d $file ]; then
14 | list_alldir $file
15 | fi
16 | done
17 | }
18 |
19 | if [ $# -gt 0 ]; then
20 | list_alldir "$1"
21 | else
22 | list_alldir "."
23 | fi
--------------------------------------------------------------------------------
/HelloWorld/proj.android/local.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 |
7 | # location of the SDK. This is only used by Ant
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/home/leafsoar/Tools/android/android-sdk-linux
11 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/ndkgdb.sh:
--------------------------------------------------------------------------------
1 | APPNAME="HelloWorld"
2 | APP_ANDROID_NAME="com.leafsoar.game"
3 |
4 | if [ -z "${SDK_ROOT+aaa}" ]; then
5 | # ... if SDK_ROOT is not set, use "$HOME/bin/android-sdk"
6 | SDK_ROOT="$HOME/bin/android-sdk"
7 | fi
8 |
9 | if [ -z "${NDK_ROOT+aaa}" ]; then
10 | # ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk"
11 | NDK_ROOT="$HOME/bin/android-ndk"
12 | fi
13 |
14 | if [ -z "${COCOS2DX_ROOT+aaa}" ]; then
15 | # ... if COCOS2DX_ROOT is not set
16 | # ... find current working directory
17 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18 | # ... use paths relative to current directory
19 | COCOS2DX_ROOT="$DIR/../.."
20 | APP_ROOT="$DIR/.."
21 | APP_ANDROID_ROOT="$DIR"
22 | else
23 | APP_ROOT="$COCOS2DX_ROOT/$APPNAME"
24 | APP_ANDROID_ROOT="$COCOS2DX_ROOT/$APPNAME/proj.android"
25 | fi
26 |
27 | echo "NDK_ROOT = $NDK_ROOT"
28 | echo "SDK_ROOT = $SDK_ROOT"
29 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
30 | echo "APP_ROOT = $APP_ROOT"
31 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
32 | echo "APP_ANDROID_NAME = $APP_ANDROID_NAME"
33 |
34 | echo
35 | echo "Killing and restarting ${APP_ANDROID_NAME}"
36 | echo
37 |
38 | set -x
39 |
40 | "${SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}"
41 |
42 | NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \
43 | "${NDK_ROOT}"/ndk-gdb \
44 | --adb="${SDK_ROOT}"/platform-tools/adb \
45 | --verbose \
46 | --start \
47 | --force
48 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-7
15 | android.library.reference.1=../../../../../Tools/android/cocos2d-x/cocos2d-2.0-x-2.0.4/cocos2dx/platform/android/java
16 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/proj.android/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/HelloWorld/proj.android/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/proj.android/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/HelloWorld/proj.android/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/HelloWorld/proj.android/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/HelloWorld/proj.android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloWorld
4 |
5 |
--------------------------------------------------------------------------------
/HelloWorld/proj.android/src/com/leafsoar/game/HelloWorld.java:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010-2012 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 | package com.leafsoar.game;
25 |
26 | import org.cocos2dx.lib.Cocos2dxActivity;
27 |
28 | import android.os.Bundle;
29 |
30 | public class HelloWorld extends Cocos2dxActivity{
31 |
32 | protected void onCreate(Bundle savedInstanceState){
33 | super.onCreate(savedInstanceState);
34 | }
35 |
36 | static {
37 | System.loadLibrary("game");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/HelloWorld/proj.linux/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /obj
3 |
--------------------------------------------------------------------------------
/HelloWorld/proj.linux/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | HelloWorld_dx
4 |
5 |
6 | libCocosDenshion
7 |
8 |
9 |
10 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
11 | clean,full,incremental,
12 |
13 |
14 | ?name?
15 |
16 |
17 |
18 | org.eclipse.cdt.make.core.append_environment
19 | true
20 |
21 |
22 | org.eclipse.cdt.make.core.autoBuildTarget
23 | all
24 |
25 |
26 | org.eclipse.cdt.make.core.buildArguments
27 |
28 |
29 |
30 | org.eclipse.cdt.make.core.buildCommand
31 | make
32 |
33 |
34 | org.eclipse.cdt.make.core.buildLocation
35 | ${workspace_loc:/HelloCocos2dx/Debug}
36 |
37 |
38 | org.eclipse.cdt.make.core.cleanBuildTarget
39 | clean
40 |
41 |
42 | org.eclipse.cdt.make.core.contents
43 | org.eclipse.cdt.make.core.activeConfigSettings
44 |
45 |
46 | org.eclipse.cdt.make.core.enableAutoBuild
47 | false
48 |
49 |
50 | org.eclipse.cdt.make.core.enableCleanBuild
51 | true
52 |
53 |
54 | org.eclipse.cdt.make.core.enableFullBuild
55 | true
56 |
57 |
58 | org.eclipse.cdt.make.core.fullBuildTarget
59 | all
60 |
61 |
62 | org.eclipse.cdt.make.core.stopOnError
63 | true
64 |
65 |
66 | org.eclipse.cdt.make.core.useDefaultBuildCmd
67 | true
68 |
69 |
70 |
71 |
72 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
73 | full,incremental,
74 |
75 |
76 |
77 |
78 |
79 | org.eclipse.cdt.core.cnature
80 | org.eclipse.cdt.core.ccnature
81 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
82 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
83 |
84 |
85 |
86 | Classes
87 | 2
88 | PARENT-1-PROJECT_LOC/Classes
89 |
90 |
91 | Resources
92 | 2
93 | PARENT-1-PROJECT_LOC/Resources
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/HelloWorld/proj.linux/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | TARGET = leafsoar
4 | CCFLAGS = -Wall
5 | CXXFLAGS = -Wall
6 | VISIBILITY =
7 |
8 | # COCOS2DX_ROOT = /home/leafsoar/...
9 |
10 | COCOS2DX_PATH = $(COCOS2DX_ROOT)/cocos2dx
11 | INCLUDES = -I../ \
12 | -I../Classes \
13 | -I$(COCOS2DX_PATH) \
14 | -I$(COCOS2DX_PATH)/platform/third_party/linux \
15 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libfreetype2 \
16 | -I$(COCOS2DX_PATH)/cocoa \
17 | -I$(COCOS2DX_PATH)/include \
18 | -I$(COCOS2DX_PATH)/platform \
19 | -I$(COCOS2DX_PATH)/platform/linux \
20 | -I$(COCOS2DX_PATH)/platform/third_party/linux/glew-1.7.0/glew-1.7.0/include/ \
21 | -I$(COCOS2DX_PATH)/kazmath/include \
22 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
23 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg \
24 | -I$(COCOS2DX_ROOT)/CocosDenshion/include \
25 | # -I$(COCOS2DX_ROOT)/extensions/ \
26 |
27 | DEFINES = -DLINUX
28 |
29 | define all-cpp-files
30 | $(patsubst ./%,%, $(shell find ../Classes ./ -name "*.cpp"))
31 | endef
32 |
33 | define all-cpp-dir
34 | $(patsubst ../%,obj/%, $(shell find ../Classes -type d))
35 | endef
36 |
37 | OBJDIR=obj/Classes
38 |
39 | OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(call all-cpp-files))
40 | OBJECTS_DIR=$(call all-cpp-dir)
41 |
42 | # 如果目录不存在,则创建相应的目录
43 | $(shell mkdir -p obj)
44 | $(shell mkdir -p $(OBJECTS_DIR))
45 |
46 | #echo:
47 | # @echo $(OBJECTS_DIR)
48 |
49 | #OBJECTS = ./main.o \
50 | # ../Classes/AppDelegate.o
51 |
52 | LBITS := $(shell getconf LONG_BIT)
53 | ifeq ($(LBITS),64)
54 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries/lib64
55 | else
56 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries
57 | endif
58 | STATICLIBS =
59 | STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
60 | $(STATICLIBS_DIR)/libxml2.a \
61 | $(STATICLIBS_DIR)/libpng.a \
62 | $(STATICLIBS_DIR)/libjpeg.a \
63 | $(STATICLIBS_DIR)/libtiff.a \
64 | # $(STATICLIBS_DIR)/libGLEW.a \
65 |
66 | SHAREDLIBS =
67 | ifeq ($(LBITS),64)
68 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/lib64/api/lib
69 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex64
70 | else
71 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/api/lib
72 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex
73 | endif
74 |
75 | SHAREDLIBS += -lglfw -lGL
76 | SHAREDLIBS += -Wl,-rpath,$(SHAREDLIBS_DIR)
77 | SHAREDLIBS += -L$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib -lGLEW
78 | SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib
79 |
80 |
81 | BIN_DIR_ROOT=bin
82 | BIN_DIR = $(BIN_DIR_ROOT)
83 |
84 | debug: BIN_DIR = $(BIN_DIR_ROOT)/debug
85 | debug: CCFLAGS += -g3 -O0
86 | debug: CXXFLAGS += -g3 -O0
87 | debug: SHAREDLIBS += -L$(COCOS2DX_ROOT)/lib/linux/Debug -lcocos2d -lrt -lz -lcocosdenshion
88 | debug: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Debug/
89 | debug: DEFINES += -DDEBUG
90 | debug: $(TARGET)
91 |
92 | release: BIN_DIR = $(BIN_DIR_ROOT)/release
93 | release: CCFLAGS += -O3
94 | release: CXXFLAGS += -O3
95 | release: SHAREDLIBS += -L.$(COCOS2DX_ROOT)/lib/linux/Release -lcocos2d -lrt -lz -lcocosdenshion
96 | release: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Release/
97 | release: DEFINES += -DNDEBUG
98 | release: $(TARGET)
99 |
100 | ####### Build rules
101 | $(TARGET): $(OBJECTS)
102 | mkdir -p $(BIN_DIR)
103 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(OBJECTS) -o $(BIN_DIR)/$(TARGET) $(SHAREDLIBS) $(STATICLIBS)
104 |
105 | ####### Compile
106 | $(OBJDIR)/%.o: %.cpp
107 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
108 |
109 | %.o: %.c
110 | $(CC) $(CCFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
111 |
112 | clean:
113 | rm -f $(OBJECTS) $(TARGET) core
114 |
--------------------------------------------------------------------------------
/HelloWorld/proj.linux/main.cpp:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "../Classes/AppDelegate.h"
3 | #include "cocos2d.h"
4 |
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | USING_NS_CC;
12 |
13 | // 500 is enough?
14 | #define MAXPATHLEN 500
15 |
16 | int main(int argc, char **argv)
17 | {
18 | // get application path
19 | int length;
20 | char fullpath[MAXPATHLEN];
21 | length = readlink("/proc/self/exe", fullpath, sizeof(fullpath));
22 | fullpath[length] = '\0';
23 |
24 | std::string resourcePath = fullpath;
25 | resourcePath = resourcePath.substr(0, resourcePath.find_last_of("/"));
26 | resourcePath += "/../../../Resources/";
27 |
28 | // create the application instance
29 | AppDelegate app;
30 | CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
31 | CCEGLView* eglView = CCEGLView::sharedOpenGLView();
32 | eglView->setFrameSize(720, 480);
33 |
34 | return CCApplication::sharedApplication()->run();
35 | }
36 |
--------------------------------------------------------------------------------
/HelloWorld/proj.linux/main.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_H__
2 | #define __MAIN_H__
3 |
4 | // C RunTime Header Files
5 | #include "CCStdC.h"
6 |
7 | #endif // __MAIN_H__
8 |
--------------------------------------------------------------------------------
/Learn/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 |
3 | #include "cocos2d.h"
4 | #include "controller.h"
5 | #include "GlobalSchedule/GlobalSchedule.h"
6 | #include "LSLog.h"
7 |
8 | USING_NS_CC;
9 |
10 | AppDelegate::AppDelegate()
11 | {
12 |
13 | }
14 |
15 | AppDelegate::~AppDelegate()
16 | {
17 |
18 | }
19 |
20 | bool AppDelegate::applicationDidFinishLaunching()
21 | {
22 | // initialize director
23 | CCDirector *pDirector = CCDirector::sharedDirector();
24 | pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
25 |
26 | // turn on display FPS
27 | pDirector->setDisplayStats(true);
28 |
29 | // set FPS. the default value is 1.0/60 ctive. Whenif you don't call this
30 | pDirector->setAnimationInterval(1.0 / 60);
31 |
32 | // create a scene. it's an autorelease object
33 | // CCScene *pScene = HelloWorld::scene();
34 |
35 | // run
36 | // pDirector->runWithScene(pScene);
37 |
38 | CCScene * pScene = CCScene::create();
39 | CCLayer * pLayer = new TestController();
40 | pLayer->autorelease();
41 |
42 | pScene->addChild(pLayer);
43 | pDirector->runWithScene(pScene);
44 |
45 | // GlobalSchedule::start(0.2f);
46 | // GlobalSchedule::pause();
47 | // GlobalSchedule::resume();
48 |
49 | // LSLog::verbose("博客名称: %s","无间落叶");
50 | // LSLog::debug("博客地址: %s", "http://blog.leafsoar.com");
51 | // LSLog::info("基本信息: %s", "吾名 一叶");
52 | // LSLog::warn("多出警告: %s %s", "警告一", "警告二");
53 | // LSLog::error("坐标错误: (%f, %f)", 800.0f, 600.0f);
54 |
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 | CCDirector::sharedDirector()->pause();
62 |
63 | // if you use SimpleAudioEngine, it must be pause
64 | // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
65 | }
66 |
67 | // this function will be called when the app is active again
68 | void AppDelegate::applicationWillEnterForeground()
69 | {
70 | CCDirector::sharedDirector()->resume();
71 |
72 | // if you use SimpleAudioEngine, it must resume here
73 | // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
74 | }
75 |
--------------------------------------------------------------------------------
/Learn/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "CCApplication.h"
5 |
6 | /**
7 | @brief The cocos2d Application.
8 |
9 | The reason for implement as private inheritance is to hide some interface call by CCDirector.
10 | */
11 | class AppDelegate : private cocos2d::CCApplication
12 | {
13 | public:
14 | AppDelegate();
15 | virtual ~AppDelegate();
16 |
17 | /**
18 | @brief Implement CCDirector and CCScene init code here.
19 | @return true Initialize success, app continue.
20 | @return false Initialize failed, app terminate.
21 | */
22 | virtual bool applicationDidFinishLaunching();
23 |
24 | /**
25 | @brief The function be called when the application enter background
26 | @param the pointer of the application
27 | */
28 | virtual void applicationDidEnterBackground();
29 |
30 | /**
31 | @brief The function be called when the application enter foreground
32 | @param the pointer of the application
33 | */
34 | virtual void applicationWillEnterForeground();
35 | };
36 |
37 | #endif // _APP_DELEGATE_H_
38 |
39 |
--------------------------------------------------------------------------------
/Learn/Classes/CustomeControl/CustomeControlTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * CustomeControlTest.cpp
3 | *
4 | * Created on: Jun 13, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "CustomeControlTest.h"
9 |
10 | void TouchScaleTestScene::runThisTest() {
11 | CCLayer* pLayer = TouchScaleTest::create();
12 | addChild(pLayer);
13 |
14 | CCDirector::sharedDirector()->replaceScene(this);
15 | }
16 |
--------------------------------------------------------------------------------
/Learn/Classes/CustomeControl/CustomeControlTest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * CustomeControlTest.h
3 | *
4 | * Created on: Jun 13, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef CUSTOMECONTROLTEST_H_
9 | #define CUSTOMECONTROLTEST_H_
10 |
11 | #include "cocos2d.h"
12 | #include "testBasic.h"
13 |
14 | USING_NS_CC;
15 |
16 | class CustomeControlTestScene: public TestScene {
17 | public:
18 | virtual void runThisTest();
19 | };
20 |
21 | class CustomeControlTest: public CCLayer {
22 | CREATE_FUNC(CustomeControlTest)
23 | ;
24 | virtual bool init();
25 | };
26 |
27 | #endif /* CUSTOMECONTROLTEST_H_ */
28 |
--------------------------------------------------------------------------------
/Learn/Classes/GlobalSchedule/GlobalSchedule.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * GlobalSchedule.cpp
3 | *
4 | * Created on: May 9, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "GlobalSchedule.h"
9 |
10 | #define SCHEDULE CCDirector::sharedDirector()->getScheduler()
11 |
12 | GlobalSchedule* GlobalSchedule::m_pSchedule = NULL;
13 |
14 | GlobalSchedule::GlobalSchedule(float fInterval, float fDelay) {
15 | CCLog("GlobalSchedule()");
16 |
17 | CCAssert(!m_pSchedule, "已定义,不能重复定义");
18 |
19 | SCHEDULE->scheduleSelector(
20 | schedule_selector(GlobalSchedule::globalUpdate), this, fInterval,
21 | false,
22 | kCCRepeatForever, fDelay);
23 |
24 | m_pSchedule = this;
25 | }
26 |
27 | GlobalSchedule::~GlobalSchedule() {
28 | CCLog("GlobalSchedule().~()");
29 |
30 | SCHEDULE->unscheduleSelector(
31 | schedule_selector(GlobalSchedule::globalUpdate), this);
32 | }
33 |
34 | void GlobalSchedule::globalUpdate() {
35 | // 这里写全局定时器的逻辑处理代码
36 | CCLog("global update");
37 | }
38 |
39 | void GlobalSchedule::start(float fInterval, float fDelay) {
40 | CCLog("GlobalSchedule().start()");
41 | new GlobalSchedule(fInterval, fDelay);
42 | }
43 |
44 | void GlobalSchedule::stop() {
45 | CCLog("GlobalSchedule().stop()");
46 |
47 | CCAssert(m_pSchedule, "未定义");
48 | CC_SAFE_DELETE(m_pSchedule);
49 | }
50 |
51 | void GlobalSchedule::pause() {
52 | CCLog("GlobalSchedule().pause()");
53 |
54 | CCAssert(m_pSchedule, "未定义");
55 | SCHEDULE->pauseTarget(m_pSchedule);
56 | }
57 |
58 | void GlobalSchedule::resume() {
59 | CCLog("GlobalSchedule().resume()");
60 |
61 | CCAssert(m_pSchedule, " 未定义");
62 | SCHEDULE->resumeTarget(m_pSchedule);
63 | }
64 |
--------------------------------------------------------------------------------
/Learn/Classes/GlobalSchedule/GlobalSchedule.h:
--------------------------------------------------------------------------------
1 | /*
2 | * GlobalSchedule.h
3 | *
4 | * Created on: May 9, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef GLOBALSCHEDULE_H_
9 | #define GLOBALSCHEDULE_H_
10 |
11 | #include "cocos2d.h"
12 |
13 | USING_NS_CC;
14 |
15 | /**
16 | * 全局定时器
17 | */
18 | class GlobalSchedule: public CCObject {
19 | public:
20 | // 开始全局定时器 fInterval: 时间间隔 ; fDelay: 延迟运行
21 | static void start(float fInterval = 0.0f, float fDelay = 0.0f);
22 | // 停止全局定时器
23 | static void stop();
24 | // 全局定时器暂停
25 | static void pause();
26 | // 全局定时器暂停恢复
27 | static void resume();
28 |
29 | // 全局定时器主逻辑实现
30 | void globalUpdate();
31 |
32 | private:
33 | // 构造函数私有化,只能通过 start 来启用全局定时器
34 | GlobalSchedule(float fInterval, float fDelay);
35 | ~GlobalSchedule();
36 |
37 | // 静态变量保持单例
38 | static GlobalSchedule* m_pSchedule;
39 | };
40 |
41 | #endif /* GLOBALSCHEDULE_H_ */
42 |
--------------------------------------------------------------------------------
/Learn/Classes/LSLog.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LSLog.cpp
3 | *
4 | * Created on: May 15, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "LSLog.h"
9 |
10 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
11 |
12 | #include "platform/android/jni/JniHelper.h"
13 | #include "platform/android/jni/Java_org_cocos2dx_lib_Cocos2dxHelper.h"
14 | #include
15 |
16 | #endif
17 |
18 | USING_NS_CC;
19 |
20 | #define kMaxStringLen (1024*100)
21 | #define LOG_V 1
22 | #define LOG_D 2
23 | #define LOG_I 4
24 | #define LOG_W 8
25 | #define LOG_E 16
26 |
27 | /// 需要打印的日志级别
28 | //const int LSLog::LOG_VALUE = LOG_V | LOG_D | LOG_I | LOG_W | LOG_E;
29 | //const int LSLog::LOG_VALUE = LOG_D | LOG_I | LOG_W | LOG_E;
30 | const int LSLog::LOG_VALUE = LOG_I | LOG_W | LOG_E;
31 | //const int LSLog::LOG_VALUE = LOG_W | LOG_E;
32 | //const int LSLog::LOG_VALUE = LOG_E;
33 | //const int LSLog::LOG_VALUE = 0;
34 |
35 | //const int LSLog::LOG_VALUE = LOG_D;
36 |
37 | void LSLog::verbose(const char * pszFormat, ...) {
38 | if (LOG_V & LOG_VALUE) {
39 | va_list ap;
40 | va_start(ap, pszFormat);
41 | LSLog::printLog(LSLOG_VERBOSE, pszFormat, ap);
42 | va_end(ap);
43 | }
44 | }
45 |
46 | void LSLog::debug(const char* pszFormat, ...) {
47 | if (LOG_D & LOG_VALUE) {
48 | va_list ap;
49 | va_start(ap, pszFormat);
50 | LSLog::printLog(LSLOG_DEBUG, pszFormat, ap);
51 | va_end(ap);
52 | }
53 | }
54 |
55 | void LSLog::info(const char* pszFormat, ...) {
56 | if (LOG_I & LOG_VALUE) {
57 | va_list ap;
58 | va_start(ap, pszFormat);
59 | LSLog::printLog(LSLOG_INFO, pszFormat, ap);
60 | va_end(ap);
61 | }
62 | }
63 |
64 | void LSLog::warn(const char* pszFormat, ...) {
65 | if (LOG_W & LOG_VALUE) {
66 | va_list ap;
67 | va_start(ap, pszFormat);
68 | LSLog::printLog(LSLOG_WARN, pszFormat, ap);
69 | va_end(ap);
70 | }
71 | }
72 |
73 | void LSLog::error(const char* pszFormat, ...) {
74 | if (LOG_E & LOG_VALUE) {
75 | va_list ap;
76 | va_start(ap, pszFormat);
77 | LSLog::printLog(LSLOG_ERROR, pszFormat, ap);
78 | va_end(ap);
79 | }
80 | }
81 |
82 | void LSLog::printLog(int type, const char* format, va_list ap) {
83 | char* pBuf = (char*) malloc(kMaxStringLen);
84 | std::string mstr;
85 | if (pBuf != NULL) {
86 | vsnprintf(pBuf, kMaxStringLen, format, ap);
87 | mstr = pBuf;
88 | free(pBuf);
89 | }
90 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
91 | printAndroidLog(lsLog_androidMethod[type].c_str(), mstr.c_str());
92 | #else
93 | CCLog("%s :%s", lsLog_name[type].c_str(), mstr.c_str());
94 | #endif
95 | }
96 |
97 | void LSLog::printAndroidLog(const char* methodName, const char* log) {
98 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
99 | JniMethodInfo t;
100 | bool isHave = JniHelper::getStaticMethodInfo(t,
101 | "android/util/Log",
102 | methodName,
103 | "(Ljava/lang/String;Ljava/lang/String;)I");
104 | if (isHave)
105 | {
106 | jstring jTitle = t.env->NewStringUTF("cocos2d-x");
107 | jstring jMsg = t.env->NewStringUTF(
108 | log);
109 | t.env->CallStaticVoidMethod(t.classID, t.methodID, jTitle,
110 | jMsg);
111 | t.env->DeleteLocalRef(jTitle);
112 | t.env->DeleteLocalRef(jMsg);
113 | }
114 | else
115 | {
116 | CCLog("the jni method is not exits");
117 | }
118 | #endif
119 | }
120 |
121 |
--------------------------------------------------------------------------------
/Learn/Classes/LSLog.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LSLog.h
3 | *
4 | * Created on: May 15, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef LSLOG_H_
9 | #define LSLOG_H_
10 |
11 | #include "cocos2d.h"
12 |
13 | enum{
14 | LSLOG_VERBOSE = 0,
15 | LSLOG_DEBUG,
16 | LSLOG_INFO,
17 | LSLOG_WARN,
18 | LSLOG_ERROR,
19 | LSLOG_COUNT,
20 | };
21 |
22 | const std::string lsLog_name[LSLOG_COUNT] = {
23 | "(verbose)\t",
24 | "(debug)\t\t",
25 | "(info)\t\t",
26 | "(warn)\t\t",
27 | "(error)\t\t"
28 | };
29 |
30 | const std::string lsLog_androidMethod[LSLOG_COUNT] = {
31 | "v",
32 | "d",
33 | "i",
34 | "w",
35 | "e"
36 | };
37 |
38 | /**
39 | @brief 自定义日志系统,前期使用,以后可以优化
40 | */
41 | class LSLog: public cocos2d::CCObject {
42 | public:
43 | /// verbose 详细日志,一般常用的打印信息
44 | static void verbose(const char * pszFormat, ...);
45 | /// debug 调试 ,调试过程所注意的信息
46 | static void debug(const char * pszFormat, ...);
47 | /// info 一般信息,
48 | static void info(const char * pszFormat, ...);
49 | /// warn 警告信息
50 | static void warn(const char * pszFormat, ...);
51 | /// error 错误信息
52 | static void error(const char * pszFormat, ...);
53 | private:
54 | static const int LOG_VALUE;
55 | static void printLog(int type, const char* format, va_list ap);
56 |
57 | static void printAndroidLog(const char* methodName, const char* log);
58 | };
59 |
60 | #endif /* LSLOG_H_ */
61 |
--------------------------------------------------------------------------------
/Learn/Classes/Property/Property.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * Property.cpp
3 | *
4 | * Created on: May 29, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "Property.h"
9 |
10 | void PropertyTestScene::runThisTest() {
11 | CCLayer* layer = PropertyTest::create();
12 | addChild(layer);
13 | CCDirector::sharedDirector()->replaceScene(this);
14 | }
15 |
16 |
--------------------------------------------------------------------------------
/Learn/Classes/Property/Property.h:
--------------------------------------------------------------------------------
1 | /*
2 | * Property.h
3 | *
4 | * Created on: May 29, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef PROPERTY_H_
9 | #define PROPERTY_H_
10 |
11 | #include "testBasic.h"
12 | #include "cocos2d.h"
13 |
14 | class PropertyTestScene: public TestScene {
15 | public:
16 | virtual void runThisTest();
17 | };
18 |
19 | // 为了方便起见,自定义宏,并且为 varName 的实现加上了 __ls_ 的前缀,前缀可以修改,可以很长很长很长
20 | // 加 __ls_ 前缀是为了,在使用的过程只通过 set 和 get 属性包装器调用,而不要直接使用此属性
21 | #define LS_PRE(p) __ls_##p
22 | //#define LS_PRE(p) __retain_##p // 其它前缀都行,目的是为了不让在直接使用此类型对象
23 |
24 | #define LS_PROPERTY_RETAIN(varType, varName, funName)\
25 | private: varType LS_PRE(varName);\
26 | public: void set##funName(varType value){\
27 | CC_SAFE_RELEASE_NULL(LS_PRE(varName));\
28 | LS_PRE(varName) = value;\
29 | CC_SAFE_RETAIN(LS_PRE(varName));\
30 | }; \
31 | public: varType get##funName(){return LS_PRE(varName);};
32 |
33 | // 初始化和释放包装宏,主要为了封装前缀,始定义统一
34 | #define LS_P_INIT(p) LS_PRE(p)(0)
35 | #define LS_P_RELEASE(p) CC_SAFE_RELEASE_NULL(LS_PRE(p))
36 |
37 | /**
38 | * 自定义类型数据:用户信息
39 | */
40 | class LUser: public cocos2d::CCObject{
41 | public:
42 | CREATE_FUNC(LUser);
43 | virtual bool init(){
44 | return true;
45 | };
46 | LUser():
47 | LS_P_INIT(m_pUser)
48 | {
49 | CCLog("LUser()");
50 | };
51 | ~LUser(){
52 | CCLog("LUser().~():%s", m_sUserName.c_str());
53 | LS_P_RELEASE(m_pUser);
54 | };
55 |
56 | std::string m_sUserName; // 用户名
57 | std::string m_sPassword; // 用户密码
58 |
59 | // 其它数据
60 | LS_PROPERTY_RETAIN(LUser*, m_pUser, User);
61 |
62 | };
63 |
64 | class PropertyTest: public CCLayer{
65 | public:
66 | CREATE_FUNC(PropertyTest);
67 |
68 | virtual bool init(){
69 | CCLog("PropertyTest().init()");
70 | LUser* lu = LUser::create();
71 | lu->m_sUserName = "leafsoar";
72 | lu->m_sPassword = "123456";
73 | setLUser(lu);
74 |
75 | // 为了方便在不同帧测试,启用定时器
76 | this->scheduleUpdate();
77 |
78 | return true;
79 | };
80 |
81 | virtual void update(float fDelta){
82 | // 为了方便观察,不让 update 内部无止境的打印下去
83 | if (updateCount < 5){
84 | updateCount ++;
85 | CCLog("update index: %d", updateCount);
86 | // 在不同的帧做相关操作,以便观察
87 | if (updateCount == 1){
88 | // 这里使用 getLUser 获取数据,而非 [__ls_]m_pLUser,所以我设置了前缀
89 | if (getLUser())
90 | CCLog("log lu: %s", getLUser()->m_sUserName.c_str());
91 |
92 | } else if (updateCount == 2){
93 | // 重新赋值
94 | LUser* lu = LUser::create();
95 | lu->m_sUserName = "一叶";
96 | LUser* luc = LUser::create();
97 | luc->m_sUserName = "无间";
98 | lu->setUser(luc);
99 | setLUser(lu);
100 | } else if (updateCount == 3){
101 | if (getLUser())
102 | CCLog("log lu: %s", getLUser()->m_sUserName.c_str());
103 | } else if (updateCount == 4){
104 | // 这里调用 seLUser(0),直接取消引用持有对象,如果不调用也没有关系
105 | // 因为在当前类析构的时候会自动检测释放
106 | // setLUser(0);
107 | }
108 | CCLog("update index: %d end", updateCount);
109 | }
110 | };
111 |
112 | // 构造函数,初始化 LS_PROPERTY_RETAIN 属性为空
113 | PropertyTest():
114 | LS_P_INIT(m_pLUser),
115 | updateCount(0)
116 | {
117 | };
118 |
119 | // 析构函数释放
120 | ~PropertyTest(){
121 | LS_P_RELEASE(m_pLUser);
122 | };
123 |
124 | // 使用 LS_PROPERTY_RETAIN 宏定义的属性,必须在构造和析构函数中初始化和释放
125 | // 初始化为 0 或者 NULL,是为了在进行赋值操作前判断时候以有引用
126 | // 析构函数释放是为了解除对持有对象的引用,如果有的话
127 | LS_PROPERTY_RETAIN(LUser*, m_pLUser, LUser);
128 |
129 | private:
130 | int updateCount;
131 | };
132 |
133 |
134 | #endif /* PROPERTY_H_ */
135 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchEventTest/LsTouch.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LsTouch.cpp
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "LsTouch.h"
9 |
10 | LsTouch::LsTouch() {
11 | CCLog("LsTouch()");
12 | m_iEventId = 0;
13 | }
14 |
15 | LsTouch::~LsTouch() {
16 | CCLog("LsTouch().~()");
17 | }
18 |
19 | bool LsTouch::init() {
20 |
21 | return true;
22 | }
23 |
24 | void LsTouch::setDisplay(CCSprite* dis) {
25 | // 设置之前先清除,没有也无所谓
26 | removeChildByTag(TAG_DISPLAY, true);
27 | addChild(dis, 0, TAG_DISPLAY);
28 | }
29 |
30 | void LsTouch::setEventId(int eventId) {
31 | m_iEventId = eventId;
32 | }
33 |
34 | int LsTouch::getEventId() {
35 | return m_iEventId;
36 | }
37 |
38 | bool LsTouch::selfCheck(CCTouch* ccTouch, LsTouchEvent* lsTe) {
39 | bool bRef = false;
40 | // 可点击项的检测,可扩展
41 | do {
42 | // 是否通过点击位置检测
43 | CC_BREAK_IF(!containsCCTouchPoint(ccTouch));
44 | // 是否正在运行,排除可能存在已经从界面移除,但是并没有释放的可能
45 | CC_BREAK_IF(!isRunning());
46 |
47 | // 判断是否隐藏
48 | CC_BREAK_IF(!isVisible());
49 | // 这里可能还需要判断内部显示项目是否隐藏
50 | ///// 暂留
51 | // 不仅判断当前元素是否隐藏,还需要判断在它之上的元素直到事件处理层,是否存在隐藏
52 | CC_BREAK_IF(!isParentAllVisible(lsTe));
53 |
54 | bRef = true;
55 | } while (0);
56 | return bRef;
57 | }
58 |
59 | bool LsTouch::containsCCTouchPoint(CCTouch* ccTouch) {
60 | // 获得显示内容
61 | CCNode* dis = getChildByTag(TAG_DISPLAY);
62 | CCSprite* sprite = dynamic_cast(dis);
63 | CCPoint point = sprite->convertTouchToNodeSpaceAR(ccTouch);
64 | CCSize s = sprite->getTexture()->getContentSize();
65 | CCRect rect = CCRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
66 | return rect.containsPoint(point);
67 | }
68 |
69 | bool LsTouch::isParentAllVisible(LsTouchEvent* lsTe) {
70 | bool bRef = true;
71 | // 向父类转型,以便获取地址比较对象,LsTouchEvent 的对象必须同时直接或者简介继承 CCNode
72 | CCNode* nLsTe = dynamic_cast(lsTe);
73 |
74 | CCNode* parent = getParent();
75 | do {
76 | // 如果遍历完毕,说明 LsTouch 不再 LsTouchEvent 之内
77 | if (!parent) {
78 | bRef = false;
79 | break;
80 | }
81 | // 如果 LsTouch 在 LsTouchEvent 之内,返回 true
82 | // 注意:如果想让LsTouchEvent 处理 不在其 CCNode 结构之内的元素,则取消此处判断
83 | if (nLsTe == parent) {
84 | break;
85 | }
86 | if (!parent->isVisible()) {
87 | bRef = false;
88 | break;
89 | }
90 | parent = parent->getParent();
91 | } while (1);
92 | return bRef;
93 | }
94 |
95 | LsTouchEvent::LsTouchEvent() {
96 | CCLog("LsTouchEvent()");
97 | m_pLsTouches = CCArray::create();
98 | m_pLsTouches->retain();
99 | }
100 |
101 | LsTouchEvent::~LsTouchEvent() {
102 | CCLog("LsTouchEvent().~()");
103 | m_pLsTouches->release();
104 | }
105 |
106 | void LsTouchEvent::addLsTouch(LsTouch* touch, int eventId) {
107 | touch->setEventId(eventId);
108 | m_pLsTouches->addObject(touch);
109 | }
110 |
111 | void LsTouchEvent::removeLsTouch(LsTouch* touch) {
112 | m_pLsTouches->removeObject(touch, true);
113 | }
114 |
115 | bool LsTouchEvent::sendTouchMessage(CCTouch* ccTouch) {
116 | // 编写判断,集合中的哪个元素级别高,就触发哪一个
117 | LsTouch* lsTouch = NULL;
118 |
119 | // 获得点击的点
120 | CCObject* pObj = NULL;
121 | LsTouch* lt = NULL;
122 | CCARRAY_FOREACH(m_pLsTouches, pObj) {
123 | lt = dynamic_cast(pObj);
124 | if (lt) {
125 | if (lt->selfCheck(ccTouch, this)) {
126 | if (lsTouch == NULL)
127 | lsTouch = lt;
128 | else
129 | // 如果已存在符合条件元素,比较优先级
130 | lsTouch = getPriorityTouch(lsTouch, lt);
131 | }
132 | }
133 | }
134 | // 比对最终只有一个元素触发
135 | if (lsTouch){
136 | touchEventAction(lsTouch);
137 | return true;
138 | }
139 | return false;
140 | }
141 |
142 | LsTouch* LsTouchEvent::getPriorityTouch(LsTouch* a, LsTouch* b) {
143 | // 触摸优先级通过 CCNode 树判断,也既是显示层次级别等因素
144 | // 以当前元素为“根”向父类转型,以便获取地址比较对象,LsTouchEvent 的对象必须同时直接或者简介继承 CCNode
145 | CCNode* nLsTe = dynamic_cast(this);
146 |
147 | // 共同的分枝
148 | CCNode* allParent = NULL;
149 | // 寻找 a 与 b 共同的分枝
150 | CCNode* nAParent = a;
151 | CCNode* nBParent = b;
152 | CCNode* nAChild = NULL;
153 | CCNode* nBChild = NULL;
154 | do {
155 | nAChild = nAParent;
156 | nAParent = nAParent->getParent();
157 | if (!nAParent)
158 | break;
159 |
160 | nBParent = b;
161 | do {
162 | nBChild = nBParent;
163 | nBParent = nBParent->getParent();
164 | if (!nBParent)
165 | break;
166 | if (nAParent == nBParent) {
167 | allParent = nAParent;
168 | break;
169 | }
170 | if (nBParent == nLsTe) {
171 | break;
172 | }
173 | } while (1);
174 | if (allParent)
175 | break;
176 | if (nAParent == nLsTe) {
177 | break;
178 | }
179 | } while (1);
180 |
181 | // 此处只需要判断 nAChild 和 nBChild 的优先级即可,默认返回 a
182 | if (!nAChild || !nBChild)
183 | return a;
184 | // 根据 ZOrder 判断,如果 ZOrder一样,根据索引位置判断
185 | if (nAChild->getZOrder() == nBChild->getZOrder())
186 | return allParent->getChildren()->indexOfObject(nAChild) > allParent->getChildren()->indexOfObject(nBChild)? a: b;
187 | else
188 | return nAChild->getZOrder() > nBChild->getZOrder()? a: b;
189 | }
190 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchEventTest/LsTouch.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LsTouch.h
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef LSTOUCH_H_
9 | #define LSTOUCH_H_
10 |
11 | #include "cocos2d.h"
12 |
13 | USING_NS_CC;
14 |
15 | class LsTouchEvent;
16 |
17 | /**
18 | * 定义可触摸元素,用于统一管理
19 | */
20 | class LsTouch: public CCNode {
21 | public:
22 | LsTouch();
23 | ~LsTouch();
24 | CREATE_FUNC(LsTouch);
25 | virtual bool init() ;
26 |
27 | // 设置显示项
28 | void setDisplay(CCSprite* dis);
29 |
30 | void setEventId(int eventId);
31 | int getEventId();
32 |
33 | /// 常规判断
34 | bool selfCheck(CCTouch* ccTouch, LsTouchEvent* lsTe);
35 |
36 | private:
37 | // 判断当前的元素是否被点击
38 | bool containsCCTouchPoint(CCTouch* ccTouch);
39 | bool isParentAllVisible(LsTouchEvent* lsTe);
40 |
41 | // 用户保存显示精灵的 tag
42 | static const int TAG_DISPLAY = 100;
43 | int m_iEventId;
44 |
45 | };
46 |
47 | class LsTouchEvent {
48 | public:
49 | LsTouchEvent();
50 | ~LsTouchEvent();
51 |
52 | void addLsTouch(LsTouch* touch, int eventId);
53 |
54 | void removeLsTouch(LsTouch* touch);
55 |
56 | bool sendTouchMessage(CCTouch* ccTouch);
57 |
58 | // 返回优先级较高的可触摸对象
59 | LsTouch* getPriorityTouch(LsTouch* a, LsTouch* b);
60 |
61 | virtual void touchEventAction(LsTouch* touch) = 0;
62 | private:
63 | CCArray* m_pLsTouches;
64 | };
65 |
66 | #endif /* LSTOUCH_H_ */
67 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchEventTest/TouchEventTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * TouchEventTest.cpp
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "TouchEventTest.h"
9 | #include "cocos2d.h"
10 |
11 | USING_NS_CC;
12 |
13 | void TouchEventTestScene::runThisTest() {
14 | CCLayer* layer = TouchEventTest::create();
15 | addChild(layer);
16 |
17 | CCDirector::sharedDirector()->replaceScene(this);
18 | }
19 |
20 | bool TouchEventTest::init() {
21 | bool bRef = false;
22 | do {
23 | CC_BREAK_IF(!CCLayer::init());
24 |
25 | // 启用触摸
26 | setTouchEnabled(true);
27 |
28 | CCSize winSize = CCDirector::sharedDirector()->getWinSize();
29 | CCPoint center = ccp(winSize.width/ 2, winSize.height / 2);
30 |
31 | // 创建可触摸精灵
32 | LsTouch* lt = LsTouch::create();
33 | // 设置位置
34 | lt->setPosition(center);
35 | // 设置显示精灵
36 | lt->setDisplay(CCSprite::create("Peas.png"));
37 | // 添加到显示
38 | this->addChild(lt);
39 | // 添加到触摸管理,第二个参数,事件 Id
40 | this->addLsTouch(lt, 100);
41 |
42 | LsTouch* lt2 = LsTouch::create();
43 | lt2->setPosition(ccpAdd(center, ccp(20, 10)));
44 | lt2->setDisplay(CCSprite::create("Peas.png"));
45 | addChild(lt2);
46 | this->addLsTouch(lt2, 101);
47 |
48 | bRef = true;
49 | } while (0);
50 |
51 | return bRef;
52 | }
53 |
54 | void TouchEventTest::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {
55 | CCSetIterator it = pTouches->begin();
56 | CCTouch* touch = (CCTouch*) (*it);
57 | // 发送触摸消息,并在 touchEventAction 自动回调相应的事件
58 | sendTouchMessage(touch);
59 | }
60 |
61 | void TouchEventTest::touchEventAction(LsTouch* touch) {
62 | CCLog("touch event action id: %d", touch->getEventId());
63 | }
64 |
65 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchEventTest/TouchEventTest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TouchEventTest.h
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef TOUCHEVENTTEST_H_
9 | #define TOUCHEVENTTEST_H_
10 |
11 | #include "testBasic.h"
12 | #include "cocos2d.h"
13 | #include "LsTouch.h"
14 |
15 | class TouchEventTestScene: public TestScene {
16 | public:
17 | virtual void runThisTest();
18 | };
19 |
20 | class TouchEventTest: public CCLayer , public LsTouchEvent{
21 | public:
22 | CREATE_FUNC(TouchEventTest)
23 | ;
24 | virtual bool init();
25 |
26 | virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
27 |
28 | virtual void touchEventAction(LsTouch* touch);
29 | };
30 |
31 |
32 | #endif /* TOUCHEVENTTEST_H_ */
33 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchScaleTest/TouchScaleTest.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * TouchScaleTest.cpp
3 | *
4 | * Created on: Apr 27, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "TouchScaleTest.h"
9 | #include "cocos2d.h"
10 |
11 | USING_NS_CC;
12 |
13 | void TouchScaleTestScene::runThisTest() {
14 | CCLayer* pLayer = TouchScaleTest::create();
15 | addChild(pLayer);
16 |
17 | CCDirector::sharedDirector()->replaceScene(this);
18 | }
19 |
20 | bool TouchScaleTest::init() {
21 | bool bRef = false;
22 | do {
23 | CC_BREAK_IF(!CCLayer::init());
24 | mSize = CCDirector::sharedDirector()->getWinSize();
25 |
26 | this->m_pBackGround = CCSprite::create("move.jpg");
27 | // 使用 anchor 为 PointZero 能更好判断其位置
28 | CCSize bgSize = m_pBackGround->getContentSize();
29 | // m_pBackGround->setPosition(
30 | // ccp(mSize.width / 2- bgSize.width / 2,mSize.height / 2 -bgSize.height / 2));
31 | m_pBackGround->setPosition(CCPointZero);
32 | m_pBackGround->setAnchorPoint(CCPointZero);
33 | addChild(m_pBackGround);
34 | // m_pBackGround->setScale(0.5);
35 |
36 | setTouchEnabled(true);
37 |
38 | bRef = true;
39 | } while (0);
40 | return bRef;
41 | }
42 |
43 | void TouchScaleTest::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {
44 | // CCSetIterator it = pTouches->begin();
45 | // CCTouch* touch = (CCTouch*) (*it);
46 |
47 | // m_tBeginPos = touch->getLocation();
48 |
49 | CCLog("touch began ...");
50 |
51 | }
52 |
53 | void TouchScaleTest::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) {
54 |
55 | CCSetIterator it = pTouches->begin();
56 | CCTouch* touch = (CCTouch*) (*it);
57 |
58 | // 获取地图区域大小
59 | CCPoint diff = touch->getDelta();
60 | CCPoint currentPos = m_pBackGround->getPosition();
61 | CCPoint newPos = ccpAdd(currentPos, diff);
62 |
63 | CCRect bound = m_pBackGround->boundingBox();
64 | // 边界检查
65 | if (newPos.x > 0)
66 | newPos.x = 0;
67 | if (newPos.y > 0)
68 | newPos.y = 0;
69 | if (newPos.x < mSize.width - bound.size.width)
70 | newPos.x = mSize.width - bound.size.width;
71 | if (newPos.y < mSize.height - bound.size.height)
72 | newPos.y = mSize.height - bound.size.height;
73 |
74 | m_pBackGround->setPosition(newPos);
75 |
76 | CCLog("touch move ...");
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/Learn/Classes/TouchScaleTest/TouchScaleTest.h:
--------------------------------------------------------------------------------
1 | /*
2 | * TouchScaleTest.h
3 | *
4 | * Created on: Apr 27, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef TOUCHSCALETEST_H_
9 | #define TOUCHSCALETEST_H_
10 |
11 | #include "testBasic.h"
12 | #include "cocos2d.h"
13 |
14 | class TouchScaleTestScene: public TestScene {
15 | public:
16 | virtual void runThisTest();
17 | };
18 |
19 | /**
20 | * 实现屏幕背景的拖动与缩放
21 | */
22 | class TouchScaleTest: public CCLayer {
23 | public:
24 | CREATE_FUNC(TouchScaleTest)
25 | ;
26 | virtual bool init();
27 |
28 | virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
29 | virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
30 | // virtual void ccTouchesEnded(CCSet *pTouches, CCEvent *pEvent);
31 |
32 | private:
33 | cocos2d::CCSize mSize; // 屏幕大小
34 | cocos2d::CCNode* m_pBackGround; // 屏幕背景
35 |
36 | int distance;
37 | int flag;
38 | int scale;
39 | };
40 |
41 | #endif /* TOUCHSCALETEST_H_ */
42 |
--------------------------------------------------------------------------------
/Learn/Classes/VisibleRect.cpp:
--------------------------------------------------------------------------------
1 | #include "VisibleRect.h"
2 |
3 | CCRect VisibleRect::s_visibleRect;
4 |
5 | void VisibleRect::lazyInit()
6 | {
7 | if (s_visibleRect.size.width == 0.0f && s_visibleRect.size.height == 0.0f)
8 | {
9 | CCEGLView* pEGLView = CCEGLView::sharedOpenGLView();
10 | s_visibleRect.origin = pEGLView->getVisibleOrigin();
11 | s_visibleRect.size = pEGLView->getVisibleSize();
12 | }
13 | }
14 |
15 | CCRect VisibleRect::getVisibleRect()
16 | {
17 | lazyInit();
18 | return CCRectMake(s_visibleRect.origin.x, s_visibleRect.origin.y, s_visibleRect.size.width, s_visibleRect.size.height);
19 | }
20 |
21 | CCPoint VisibleRect::left()
22 | {
23 | lazyInit();
24 | return ccp(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height/2);
25 | }
26 |
27 | CCPoint VisibleRect::right()
28 | {
29 | lazyInit();
30 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height/2);
31 | }
32 |
33 | CCPoint VisibleRect::top()
34 | {
35 | lazyInit();
36 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height);
37 | }
38 |
39 | CCPoint VisibleRect::bottom()
40 | {
41 | lazyInit();
42 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y);
43 | }
44 |
45 | CCPoint VisibleRect::center()
46 | {
47 | lazyInit();
48 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width/2, s_visibleRect.origin.y+s_visibleRect.size.height/2);
49 | }
50 |
51 | CCPoint VisibleRect::leftTop()
52 | {
53 | lazyInit();
54 | return ccp(s_visibleRect.origin.x, s_visibleRect.origin.y+s_visibleRect.size.height);
55 | }
56 |
57 | CCPoint VisibleRect::rightTop()
58 | {
59 | lazyInit();
60 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y+s_visibleRect.size.height);
61 | }
62 |
63 | CCPoint VisibleRect::leftBottom()
64 | {
65 | lazyInit();
66 | return s_visibleRect.origin;
67 | }
68 |
69 | CCPoint VisibleRect::rightBottom()
70 | {
71 | lazyInit();
72 | return ccp(s_visibleRect.origin.x+s_visibleRect.size.width, s_visibleRect.origin.y);
73 | }
74 |
--------------------------------------------------------------------------------
/Learn/Classes/VisibleRect.h:
--------------------------------------------------------------------------------
1 | #ifndef __VISIBLERECT_H__
2 | #define __VISIBLERECT_H__
3 |
4 | #include "cocos2d.h"
5 | USING_NS_CC;
6 |
7 | class VisibleRect
8 | {
9 | public:
10 | static CCRect getVisibleRect();
11 |
12 | static CCPoint left();
13 | static CCPoint right();
14 | static CCPoint top();
15 | static CCPoint bottom();
16 | static CCPoint center();
17 | static CCPoint leftTop();
18 | static CCPoint rightTop();
19 | static CCPoint leftBottom();
20 | static CCPoint rightBottom();
21 | private:
22 | static void lazyInit();
23 | static CCRect s_visibleRect;
24 | };
25 |
26 | #endif /* __VISIBLERECT_H__ */
27 |
--------------------------------------------------------------------------------
/Learn/Classes/controller.cpp:
--------------------------------------------------------------------------------
1 | #include "controller.h"
2 | #include "testResource.h"
3 | #include "tests.h"
4 | #include "GlobalSchedule/GlobalSchedule.h"
5 |
6 | #define LINE_SPACE 50
7 |
8 | static CCPoint s_tCurPos = CCPointZero;
9 |
10 | static TestScene* CreateTestScene(int nIdx) {
11 | CCDirector::sharedDirector()->purgeCachedData();
12 |
13 | TestScene* pScene = NULL;
14 |
15 | switch (nIdx) {
16 | case TEST_TOUCH_SCALE:
17 | pScene = new TouchScaleTestScene();
18 | break;
19 | case TEST_TOUCH_EVENT:
20 | pScene = new TouchEventTestScene();
21 | break;
22 | case TEST_RETAIN_PROPERTY:
23 | pScene = new PropertyTestScene();
24 | break;
25 | default:
26 | break;
27 | }
28 |
29 | return pScene;
30 | }
31 |
32 | TestController::TestController() :
33 | m_tBeginPos(CCPointZero) {
34 | // add close menu
35 | CCMenuItemImage *pCloseItem = CCMenuItemImage::create(s_pClose, s_pClose,
36 | this, menu_selector(TestController::closeCallback));
37 | CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
38 |
39 | pMenu->setPosition(CCPointZero);
40 | pCloseItem->setPosition(
41 | ccp( VisibleRect::right().x - 40, 40));
42 |
43 | // add menu items for tests
44 | m_pItemMenu = CCMenu::create();
45 | for (int i = 0; i < TESTS_COUNT; ++i) {
46 | // #if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
47 | // CCLabelBMFont* label = CCLabelBMFont::create(g_aTestNames[i].c_str(), "fonts/arial16.fnt");
48 | // #else
49 | CCLabelTTF* label = CCLabelTTF::create(g_aTestNames[i].c_str(),
50 | sf_defaultFont, 36);
51 | // #endif
52 | CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this,
53 | menu_selector(TestController::menuCallback));
54 |
55 | m_pItemMenu->addChild(pMenuItem, i + 10000);
56 | pMenuItem->setPosition(
57 | ccp( VisibleRect::center().x, (VisibleRect::top().y - (i + 1) * LINE_SPACE) ));
58 | }
59 |
60 | m_pItemMenu->setContentSize(
61 | CCSizeMake(VisibleRect::getVisibleRect().size.width, (TESTS_COUNT + 1) * (LINE_SPACE)));
62 | m_pItemMenu->setPosition(s_tCurPos);
63 | addChild(m_pItemMenu);
64 |
65 | setTouchEnabled(true);
66 |
67 | addChild(pMenu, 1);
68 |
69 | }
70 |
71 | TestController::~TestController() {
72 | }
73 |
74 | void TestController::menuCallback(CCObject * pSender) {
75 | // get the userdata, it's the index of the menu item clicked
76 | CCMenuItem* pMenuItem = (CCMenuItem *) (pSender);
77 | int nIdx = pMenuItem->getZOrder() - 10000;
78 |
79 | // create the test scene and run it
80 | TestScene* pScene = CreateTestScene(nIdx);
81 | if (pScene) {
82 | pScene->runThisTest();
83 | pScene->release();
84 | }
85 | }
86 |
87 | void TestController::closeCallback(CCObject * pSender) {
88 | CCDirector::sharedDirector()->end();
89 | // GlobalSchedule::stop();
90 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
91 | exit(0);
92 | #endif
93 | }
94 |
95 | void TestController::ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent) {
96 | CCSetIterator it = pTouches->begin();
97 | CCTouch* touch = (CCTouch*) (*it);
98 |
99 | m_tBeginPos = touch->getLocation();
100 | }
101 |
102 | void TestController::ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent) {
103 | CCSetIterator it = pTouches->begin();
104 | CCTouch* touch = (CCTouch*) (*it);
105 |
106 | CCPoint touchLocation = touch->getLocation();
107 | float nMoveY = touchLocation.y - m_tBeginPos.y;
108 |
109 | CCPoint curPos = m_pItemMenu->getPosition();
110 | CCPoint nextPos = ccp(curPos.x, curPos.y + nMoveY);
111 |
112 | if (nextPos.y < 0.0f) {
113 | m_pItemMenu->setPosition(CCPointZero);
114 | return;
115 | }
116 |
117 | if ((TESTS_COUNT + 1) * LINE_SPACE
118 | < VisibleRect::getVisibleRect().size.height) {
119 | m_pItemMenu->setPosition(CCPointZero);
120 | return;
121 | }
122 |
123 | if (nextPos.y
124 | > ((TESTS_COUNT + 1) * LINE_SPACE
125 | - VisibleRect::getVisibleRect().size.height)) {
126 | m_pItemMenu->setPosition(
127 | ccp(0, ((TESTS_COUNT + 1)* LINE_SPACE - VisibleRect::getVisibleRect().size.height)));
128 | return;
129 | }
130 |
131 | m_pItemMenu->setPosition(nextPos);
132 | m_tBeginPos = touchLocation;
133 | s_tCurPos = nextPos;
134 | }
135 |
--------------------------------------------------------------------------------
/Learn/Classes/controller.h:
--------------------------------------------------------------------------------
1 | #ifndef _CONTROLLER_H_
2 | #define _CONTROLLER_H_
3 |
4 | #include "cocos2d.h"
5 |
6 | USING_NS_CC;
7 |
8 | class TestController : public CCLayer
9 | {
10 | public:
11 | TestController();
12 | ~TestController();
13 |
14 | void menuCallback(CCObject * pSender);
15 | void closeCallback(CCObject * pSender);
16 |
17 | virtual void ccTouchesBegan(CCSet *pTouches, CCEvent *pEvent);
18 | virtual void ccTouchesMoved(CCSet *pTouches, CCEvent *pEvent);
19 |
20 | private:
21 | CCPoint m_tBeginPos;
22 | CCMenu* m_pItemMenu;
23 | };
24 |
25 | #endif
26 |
--------------------------------------------------------------------------------
/Learn/Classes/testBasic.cpp:
--------------------------------------------------------------------------------
1 | #include "testBasic.h"
2 | #include "controller.h"
3 |
4 | TestScene::TestScene(bool bPortrait)
5 | {
6 |
7 | CCScene::init();
8 | }
9 |
10 | void TestScene::onEnter()
11 | {
12 | CCScene::onEnter();
13 |
14 | //add the menu item for back to main menu
15 | //#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
16 | // CCLabelBMFont* label = CCLabelBMFont::create("MainMenu", "fonts/arial16.fnt");
17 | //#else
18 | CCLabelTTF* label = CCLabelTTF::create("MainMenu", "Arial", 30);
19 | //#endif
20 | CCMenuItemLabel* pMenuItem = CCMenuItemLabel::create(label, this, menu_selector(TestScene::MainMenuCallback));
21 |
22 | CCMenu* pMenu =CCMenu::create(pMenuItem, NULL);
23 |
24 | pMenu->setPosition( CCPointZero );
25 | pMenuItem->setPosition( ccp( VisibleRect::right().x - 100, VisibleRect::bottom().y + 25) );
26 |
27 | addChild(pMenu, 1);
28 | }
29 |
30 | void TestScene::MainMenuCallback(CCObject* pSender)
31 | {
32 | CCScene* pScene = CCScene::create();
33 | CCLayer* pLayer = new TestController();
34 | pLayer->autorelease();
35 |
36 | pScene->addChild(pLayer);
37 | CCDirector::sharedDirector()->replaceScene(pScene);
38 | }
39 |
--------------------------------------------------------------------------------
/Learn/Classes/testBasic.h:
--------------------------------------------------------------------------------
1 | #ifndef _TEST_BASIC_H_
2 | #define _TEST_BASIC_H_
3 |
4 | #include "cocos2d.h"
5 | #include "VisibleRect.h"
6 |
7 | USING_NS_CC;
8 | using namespace std;
9 |
10 | class TestScene : public CCScene
11 | {
12 | public:
13 | TestScene(bool bPortrait = false);
14 | virtual void onEnter();
15 |
16 | virtual void runThisTest() = 0;
17 |
18 | // The CallBack for back to the main menu scene
19 | virtual void MainMenuCallback(CCObject* pSender);
20 | };
21 |
22 | #endif
23 |
--------------------------------------------------------------------------------
/Learn/Classes/testResource.h:
--------------------------------------------------------------------------------
1 | #ifndef _TEST_RESOURCE_H_
2 | #define _TEST_RESOURCE_H_
3 |
4 | static const char sf_defaultFont[] = "SimHei"; // 默认字体
5 | static const char s_pClose[] = "close.png";
6 |
7 |
8 | #endif
9 |
--------------------------------------------------------------------------------
/Learn/Classes/tests.h:
--------------------------------------------------------------------------------
1 | #ifndef _TESTS_H_
2 | #define _TESTS_H_
3 |
4 | //#include "ActionsTest/ActionsTest.h"
5 | #include "TouchScaleTest/TouchScaleTest.h"
6 | #include "TouchEventTest/TouchEventTest.h"
7 | #include "Property/Property.h"
8 |
9 | enum {
10 | TEST_TOUCH_SCALE = 0,
11 | TEST_TOUCH_EVENT,
12 | TEST_RETAIN_PROPERTY,
13 | TESTS_COUNT,
14 | };
15 |
16 | const std::string g_aTestNames[TESTS_COUNT] = {
17 | "Touch Scale",
18 | "Touch Event",
19 | "Retain Property"};
20 |
21 | #endif
22 |
--------------------------------------------------------------------------------
/Learn/README.md:
--------------------------------------------------------------------------------
1 | # Learn 项目代码
2 |
3 | 源代码路径: ./Classes
4 |
5 | 资源文件路径: ./../Resources
6 |
--------------------------------------------------------------------------------
/Learn/proj.android/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/Learn/proj.android/.gitignore:
--------------------------------------------------------------------------------
1 | /gen
2 | /assets
3 | /bin
4 | /libs
5 | /obj
6 |
--------------------------------------------------------------------------------
/Learn/proj.android/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Learn_j
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/Learn/proj.android/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 |
9 |
12 |
13 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
28 |
29 |
--------------------------------------------------------------------------------
/Learn/proj.android/ant.properties:
--------------------------------------------------------------------------------
1 | # This file is used to override default values used by the Ant build system.
2 | #
3 | # This file must be checked into Version Control Systems, as it is
4 | # integral to the build system of your project.
5 |
6 | # This file is only used by the Ant script.
7 |
8 | # You can use this to override default values such as
9 | # 'source.dir' for the location of your java source folder and
10 | # 'out.dir' for the location of your output folder.
11 |
12 | # You can also use it define how the release builds are signed by declaring
13 | # the following properties:
14 | # 'key.store' for the location of your keystore and
15 | # 'key.alias' for the name of the key to use.
16 | # The password will be asked during the build when you use the 'release' target.
17 |
18 |
--------------------------------------------------------------------------------
/Learn/proj.android/build.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
29 |
30 |
31 |
35 |
36 |
37 |
38 |
39 |
40 |
49 |
50 |
51 |
52 |
56 |
57 |
69 |
70 |
71 |
89 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/Learn/proj.android/build_native.sh:
--------------------------------------------------------------------------------
1 | APPNAME="HelloWorld"
2 |
3 | # options
4 |
5 | buildexternalsfromsource=
6 |
7 | usage(){
8 | cat << EOF
9 | usage: $0 [options]
10 |
11 | Build C/C++ code for $APPNAME using Android NDK
12 |
13 | OPTIONS:
14 | -s Build externals from source
15 | -h this help
16 | EOF
17 | }
18 |
19 | while getopts "sh" OPTION; do
20 | case "$OPTION" in
21 | s)
22 | buildexternalsfromsource=1
23 | ;;
24 | h)
25 | usage
26 | exit 0
27 | ;;
28 | esac
29 | done
30 |
31 | # paths
32 |
33 | if [ -z "${NDK_ROOT+aaa}" ];then
34 | echo "please define NDK_ROOT"
35 | exit 1
36 | fi
37 |
38 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
39 | # ... use paths relative to current directory
40 | COCOS2DX_ROOT="/home/leafsoar/Tools/android/cocos2d-x/cocos2d-2.0-x-2.0.4"
41 | APP_ROOT="$DIR/.."
42 | APP_ANDROID_ROOT="$DIR"
43 |
44 | echo "NDK_ROOT = $NDK_ROOT"
45 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
46 | echo "APP_ROOT = $APP_ROOT"
47 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
48 |
49 | # make sure assets is exist
50 | if [ -d "$APP_ANDROID_ROOT"/assets ]; then
51 | rm -rf "$APP_ANDROID_ROOT"/assets
52 | fi
53 |
54 | mkdir "$APP_ANDROID_ROOT"/assets
55 |
56 | # copy resources
57 | for file in "$APP_ROOT"/../Resources/*
58 | do
59 | if [ -d "$file" ]; then
60 | cp -rf "$file" "$APP_ANDROID_ROOT"/assets
61 | fi
62 |
63 | if [ -f "$file" ]; then
64 | cp "$file" "$APP_ANDROID_ROOT"/assets
65 | fi
66 | done
67 |
68 | # copy icons (if they exist)
69 | file="$APP_ANDROID_ROOT"/assets/Icon-72.png
70 | if [ -f "$file" ]; then
71 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-hdpi/icon.png
72 | fi
73 | file="$APP_ANDROID_ROOT"/assets/Icon-48.png
74 | if [ -f "$file" ]; then
75 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-mdpi/icon.png
76 | fi
77 | file="$APP_ANDROID_ROOT"/assets/Icon-32.png
78 | if [ -f "$file" ]; then
79 | cp "$file" "$APP_ANDROID_ROOT"/res/drawable-ldpi/icon.png
80 | fi
81 |
82 |
83 | if [[ "$buildexternalsfromsource" ]]; then
84 | echo "Building external dependencies from source"
85 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
86 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/source"
87 | else
88 | echo "Using prebuilt externals"
89 | "$NDK_ROOT"/ndk-build -C "$APP_ANDROID_ROOT" $* \
90 | "NDK_MODULE_PATH=${COCOS2DX_ROOT}:${COCOS2DX_ROOT}/cocos2dx/platform/third_party/android/prebuilt"
91 | fi
92 |
--------------------------------------------------------------------------------
/Learn/proj.android/jni/Android.mk:
--------------------------------------------------------------------------------
1 | LOCAL_PATH := $(call my-dir)
2 |
3 | include $(CLEAR_VARS)
4 |
5 | LOCAL_MODULE := game_shared
6 |
7 | LOCAL_MODULE_FILENAME := libgame
8 |
9 | define all-cpp-files
10 | $(patsubst jni/%,%, $(shell find $(LOCAL_PATH)/../../Classes/ $(LOCAL_PATH)/hellocpp -name "*.cpp"))
11 | endef
12 |
13 | LOCAL_SRC_FILES := $(call all-cpp-files)
14 |
15 | LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
16 |
17 | LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
18 |
19 | include $(BUILD_SHARED_LIBRARY)
20 |
21 | $(call import-module,CocosDenshion/android) \
22 | $(call import-module,cocos2dx) \
23 | $(call import-module,extensions)
24 |
--------------------------------------------------------------------------------
/Learn/proj.android/jni/Application.mk:
--------------------------------------------------------------------------------
1 | APP_STL := gnustl_static
2 | APP_CPPFLAGS := -frtti
--------------------------------------------------------------------------------
/Learn/proj.android/jni/hellocpp/main.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 | #include "platform/android/jni/JniHelper.h"
3 | #include
4 | #include
5 | #include "controller.h"
6 |
7 | #define LOG_TAG "main"
8 | #define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
9 |
10 | using namespace cocos2d;
11 |
12 | extern "C"
13 | {
14 |
15 | jint JNI_OnLoad(JavaVM *vm, void *reserved)
16 | {
17 | JniHelper::setJavaVM(vm);
18 |
19 | return JNI_VERSION_1_4;
20 | }
21 |
22 | void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
23 | {
24 | if (!CCDirector::sharedDirector()->getOpenGLView())
25 | {
26 | CCEGLView *view = CCEGLView::sharedOpenGLView();
27 | view->setFrameSize(w, h);
28 |
29 | AppDelegate *pAppDelegate = new AppDelegate();
30 | CCApplication::sharedApplication()->run();
31 | }
32 | else
33 | {
34 | ccDrawInit();
35 | ccGLInvalidateStateCache();
36 |
37 | CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
38 | CCTextureCache::reloadAllTextures();
39 | CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
40 | CCDirector::sharedDirector()->setGLDefaultValues();
41 | }
42 | }
43 |
44 | }
45 |
--------------------------------------------------------------------------------
/Learn/proj.android/jni/list.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | append_str=' \'
4 |
5 | list_alldir()
6 | {
7 | for file in $1/*
8 | do
9 | if [ -f $file ]; then
10 | echo $file$append_str | grep .cpp
11 | fi
12 |
13 | if [ -d $file ]; then
14 | list_alldir $file
15 | fi
16 | done
17 | }
18 |
19 | if [ $# -gt 0 ]; then
20 | list_alldir "$1"
21 | else
22 | list_alldir "."
23 | fi
--------------------------------------------------------------------------------
/Learn/proj.android/local.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must *NOT* be checked into Version Control Systems,
5 | # as it contains information specific to your local configuration.
6 |
7 | # location of the SDK. This is only used by Ant
8 | # For customization when using a Version Control System, please read the
9 | # header note.
10 | sdk.dir=/home/leafsoar/Tools/android/android-sdk-linux
11 |
--------------------------------------------------------------------------------
/Learn/proj.android/ndkgdb.sh:
--------------------------------------------------------------------------------
1 | APPNAME="HelloWorld"
2 | APP_ANDROID_NAME="com.leafsoar.game"
3 |
4 | if [ -z "${SDK_ROOT+aaa}" ]; then
5 | # ... if SDK_ROOT is not set, use "$HOME/bin/android-sdk"
6 | SDK_ROOT="$HOME/bin/android-sdk"
7 | fi
8 |
9 | if [ -z "${NDK_ROOT+aaa}" ]; then
10 | # ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk"
11 | NDK_ROOT="$HOME/bin/android-ndk"
12 | fi
13 |
14 | if [ -z "${COCOS2DX_ROOT+aaa}" ]; then
15 | # ... if COCOS2DX_ROOT is not set
16 | # ... find current working directory
17 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
18 | # ... use paths relative to current directory
19 | COCOS2DX_ROOT="$DIR/../.."
20 | APP_ROOT="$DIR/.."
21 | APP_ANDROID_ROOT="$DIR"
22 | else
23 | APP_ROOT="$COCOS2DX_ROOT/$APPNAME"
24 | APP_ANDROID_ROOT="$COCOS2DX_ROOT/$APPNAME/proj.android"
25 | fi
26 |
27 | echo "NDK_ROOT = $NDK_ROOT"
28 | echo "SDK_ROOT = $SDK_ROOT"
29 | echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
30 | echo "APP_ROOT = $APP_ROOT"
31 | echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
32 | echo "APP_ANDROID_NAME = $APP_ANDROID_NAME"
33 |
34 | echo
35 | echo "Killing and restarting ${APP_ANDROID_NAME}"
36 | echo
37 |
38 | set -x
39 |
40 | "${SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}"
41 |
42 | NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \
43 | "${NDK_ROOT}"/ndk-gdb \
44 | --adb="${SDK_ROOT}"/platform-tools/adb \
45 | --verbose \
46 | --start \
47 | --force
48 |
--------------------------------------------------------------------------------
/Learn/proj.android/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/Learn/proj.android/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-7
15 | android.library.reference.1=../../../../../Tools/android/cocos2d-x/cocos2d-2.0-x-2.0.4/cocos2dx/platform/android/java
16 |
--------------------------------------------------------------------------------
/Learn/proj.android/res/drawable-hdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Learn/proj.android/res/drawable-hdpi/icon.png
--------------------------------------------------------------------------------
/Learn/proj.android/res/drawable-ldpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Learn/proj.android/res/drawable-ldpi/icon.png
--------------------------------------------------------------------------------
/Learn/proj.android/res/drawable-mdpi/icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Learn/proj.android/res/drawable-mdpi/icon.png
--------------------------------------------------------------------------------
/Learn/proj.android/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | lsLearn
4 |
5 |
--------------------------------------------------------------------------------
/Learn/proj.android/src/com/leafsoar/game/learn/HelloWorld.java:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010-2012 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 | package com.leafsoar.game.learn;
25 |
26 | import org.cocos2dx.lib.Cocos2dxActivity;
27 |
28 | import android.os.Bundle;
29 |
30 | public class HelloWorld extends Cocos2dxActivity{
31 |
32 | protected void onCreate(Bundle savedInstanceState){
33 | super.onCreate(savedInstanceState);
34 | }
35 |
36 | static {
37 | System.loadLibrary("game");
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/Learn/proj.linux/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /obj
3 |
--------------------------------------------------------------------------------
/Learn/proj.linux/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Learn
4 |
5 |
6 | libCocosDenshion
7 |
8 |
9 |
10 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
11 | clean,full,incremental,
12 |
13 |
14 | ?name?
15 |
16 |
17 |
18 | org.eclipse.cdt.make.core.append_environment
19 | true
20 |
21 |
22 | org.eclipse.cdt.make.core.autoBuildTarget
23 | all
24 |
25 |
26 | org.eclipse.cdt.make.core.buildArguments
27 |
28 |
29 |
30 | org.eclipse.cdt.make.core.buildCommand
31 | make
32 |
33 |
34 | org.eclipse.cdt.make.core.buildLocation
35 | ${workspace_loc:/HelloCocos2dx/Debug}
36 |
37 |
38 | org.eclipse.cdt.make.core.cleanBuildTarget
39 | clean
40 |
41 |
42 | org.eclipse.cdt.make.core.contents
43 | org.eclipse.cdt.make.core.activeConfigSettings
44 |
45 |
46 | org.eclipse.cdt.make.core.enableAutoBuild
47 | false
48 |
49 |
50 | org.eclipse.cdt.make.core.enableCleanBuild
51 | true
52 |
53 |
54 | org.eclipse.cdt.make.core.enableFullBuild
55 | true
56 |
57 |
58 | org.eclipse.cdt.make.core.fullBuildTarget
59 | all
60 |
61 |
62 | org.eclipse.cdt.make.core.stopOnError
63 | true
64 |
65 |
66 | org.eclipse.cdt.make.core.useDefaultBuildCmd
67 | true
68 |
69 |
70 |
71 |
72 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
73 | full,incremental,
74 |
75 |
76 |
77 |
78 |
79 | org.eclipse.cdt.core.cnature
80 | org.eclipse.cdt.core.ccnature
81 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
82 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
83 |
84 |
85 |
86 | Classes
87 | 2
88 | PARENT-1-PROJECT_LOC/Classes
89 |
90 |
91 | Resources
92 | 2
93 | PARENT-2-PROJECT_LOC/Resources
94 |
95 |
96 |
97 |
98 | copy_PARENT
99 | $%7BPARENT-1-PROJECT_LOC%7D/ls-cocos2d-x/Learn
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/Learn/proj.linux/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | TARGET = leafsoar
4 | CCFLAGS = -Wall
5 | CXXFLAGS = -Wall
6 | VISIBILITY =
7 |
8 | # COCOS2DX_ROOT = /home/leafsoar/...
9 |
10 | COCOS2DX_PATH = $(COCOS2DX_ROOT)/cocos2dx
11 | INCLUDES = -I../ \
12 | -I../Classes \
13 | -I$(COCOS2DX_PATH) \
14 | -I$(COCOS2DX_PATH)/platform/third_party/linux \
15 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libfreetype2 \
16 | -I$(COCOS2DX_PATH)/cocoa \
17 | -I$(COCOS2DX_PATH)/include \
18 | -I$(COCOS2DX_PATH)/platform \
19 | -I$(COCOS2DX_PATH)/platform/linux \
20 | -I$(COCOS2DX_PATH)/platform/third_party/linux/glew-1.7.0/glew-1.7.0/include/ \
21 | -I$(COCOS2DX_PATH)/kazmath/include \
22 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
23 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg \
24 | -I$(COCOS2DX_ROOT)/CocosDenshion/include \
25 | # -I$(COCOS2DX_ROOT)/extensions/ \
26 |
27 | DEFINES = -DLINUX
28 |
29 | define all-cpp-files
30 | $(patsubst ./%,%, $(shell find ../Classes ./ -name "*.cpp"))
31 | endef
32 |
33 | define all-cpp-dir
34 | $(patsubst ../%,obj/%, $(shell find ../Classes -type d))
35 | endef
36 |
37 | OBJDIR=obj/Classes
38 |
39 | OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(call all-cpp-files))
40 | OBJECTS_DIR=$(call all-cpp-dir)
41 |
42 | # 如果目录不存在,则创建相应的目录
43 | $(shell mkdir -p obj)
44 | $(shell mkdir -p $(OBJECTS_DIR))
45 |
46 | #echo:
47 | # @echo $(OBJECTS_DIR)
48 |
49 | #OBJECTS = ./main.o \
50 | # ../Classes/AppDelegate.o
51 |
52 | LBITS := $(shell getconf LONG_BIT)
53 | ifeq ($(LBITS),64)
54 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries/lib64
55 | else
56 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries
57 | endif
58 | STATICLIBS =
59 | STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
60 | $(STATICLIBS_DIR)/libxml2.a \
61 | $(STATICLIBS_DIR)/libpng.a \
62 | $(STATICLIBS_DIR)/libjpeg.a \
63 | $(STATICLIBS_DIR)/libtiff.a \
64 | # $(STATICLIBS_DIR)/libGLEW.a \
65 |
66 | SHAREDLIBS =
67 | ifeq ($(LBITS),64)
68 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/lib64/api/lib
69 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex64
70 | else
71 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/api/lib
72 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex
73 | endif
74 |
75 | SHAREDLIBS += -lglfw -lGL
76 | SHAREDLIBS += -Wl,-rpath,$(SHAREDLIBS_DIR)
77 | SHAREDLIBS += -L$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib -lGLEW
78 | SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib
79 |
80 |
81 | BIN_DIR_ROOT=bin
82 | BIN_DIR = $(BIN_DIR_ROOT)
83 |
84 | debug: BIN_DIR = $(BIN_DIR_ROOT)/debug
85 | debug: CCFLAGS += -g3 -O0
86 | debug: CXXFLAGS += -g3 -O0
87 | debug: SHAREDLIBS += -L$(COCOS2DX_ROOT)/lib/linux/Debug -lcocos2d -lrt -lz -lcocosdenshion
88 | debug: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Debug/
89 | debug: DEFINES += -DDEBUG
90 | debug: $(TARGET)
91 |
92 | release: BIN_DIR = $(BIN_DIR_ROOT)/release
93 | release: CCFLAGS += -O3
94 | release: CXXFLAGS += -O3
95 | release: SHAREDLIBS += -L.$(COCOS2DX_ROOT)/lib/linux/Release -lcocos2d -lrt -lz -lcocosdenshion
96 | release: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Release/
97 | release: DEFINES += -DNDEBUG
98 | release: $(TARGET)
99 |
100 | ####### Build rules
101 | $(TARGET): $(OBJECTS)
102 | mkdir -p $(BIN_DIR)
103 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(OBJECTS) -o $(BIN_DIR)/$(TARGET) $(SHAREDLIBS) $(STATICLIBS)
104 |
105 | ####### Compile
106 | $(OBJDIR)/%.o: %.cpp
107 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
108 |
109 | %.o: %.c
110 | $(CC) $(CCFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
111 |
112 | clean:
113 | rm -f $(OBJECTS) $(TARGET) core
114 |
--------------------------------------------------------------------------------
/Learn/proj.linux/main.cpp:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "../Classes/AppDelegate.h"
3 | #include "cocos2d.h"
4 |
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | USING_NS_CC;
12 |
13 | // 500 is enough?
14 | #define MAXPATHLEN 500
15 |
16 | int main(int argc, char **argv)
17 | {
18 | // get application path
19 | int length;
20 | char fullpath[MAXPATHLEN];
21 | length = readlink("/proc/self/exe", fullpath, sizeof(fullpath));
22 | fullpath[length] = '\0';
23 |
24 | std::string resourcePath = fullpath;
25 | resourcePath = resourcePath.substr(0, resourcePath.find_last_of("/"));
26 | resourcePath += "/../../../../Resources/";
27 |
28 | // create the application instance
29 | AppDelegate app;
30 | CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
31 | CCEGLView* eglView = CCEGLView::sharedOpenGLView();
32 | eglView->setFrameSize(720, 480);
33 |
34 | return CCApplication::sharedApplication()->run();
35 | }
36 |
--------------------------------------------------------------------------------
/Learn/proj.linux/main.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_H__
2 | #define __MAIN_H__
3 |
4 | // C RunTime Header Files
5 | #include "CCStdC.h"
6 |
7 | #endif // __MAIN_H__
8 |
--------------------------------------------------------------------------------
/Libs/README.md:
--------------------------------------------------------------------------------
1 | # 第三方库源文件
2 |
3 | Json 解析生成库 rapidjson 0.11
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/filestream.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_FILESTREAM_H_
2 | #define RAPIDJSON_FILESTREAM_H_
3 |
4 | #include
5 |
6 | namespace rapidjson {
7 |
8 | //! Wrapper of C file stream for input or output.
9 | /*!
10 | This simple wrapper does not check the validity of the stream.
11 | \implements Stream
12 | */
13 | class FileStream {
14 | public:
15 | typedef char Ch; //!< Character type. Only support char.
16 |
17 | FileStream(FILE* fp) : fp_(fp), count_(0) { Read(); }
18 | char Peek() const { return current_; }
19 | char Take() { char c = current_; Read(); return c; }
20 | size_t Tell() const { return count_; }
21 | void Put(char c) { fputc(c, fp_); }
22 |
23 | // Not implemented
24 | char* PutBegin() { return 0; }
25 | size_t PutEnd(char*) { return 0; }
26 |
27 | private:
28 | void Read() {
29 | RAPIDJSON_ASSERT(fp_ != 0);
30 | int c = fgetc(fp_);
31 | if (c != EOF) {
32 | current_ = (char)c;
33 | count_++;
34 | }
35 | else
36 | current_ = '\0';
37 | }
38 |
39 | FILE* fp_;
40 | char current_;
41 | size_t count_;
42 | };
43 |
44 | } // namespace rapidjson
45 |
46 | #endif // RAPIDJSON_FILESTREAM_H_
47 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/internal/pow10.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_POW10_
2 | #define RAPIDJSON_POW10_
3 |
4 | namespace rapidjson {
5 | namespace internal {
6 |
7 | //! Computes integer powers of 10 in double (10.0^n).
8 | /*! This function uses lookup table for fast and accurate results.
9 | \param n positive/negative exponent. Must <= 308.
10 | \return 10.0^n
11 | */
12 | inline double Pow10(int n) {
13 | static const double e[] = { // 1e-308...1e308: 617 * 8 bytes = 4936 bytes
14 | 1e-308,1e-307,1e-306,1e-305,1e-304,1e-303,1e-302,1e-301,1e-300,
15 | 1e-299,1e-298,1e-297,1e-296,1e-295,1e-294,1e-293,1e-292,1e-291,1e-290,1e-289,1e-288,1e-287,1e-286,1e-285,1e-284,1e-283,1e-282,1e-281,1e-280,
16 | 1e-279,1e-278,1e-277,1e-276,1e-275,1e-274,1e-273,1e-272,1e-271,1e-270,1e-269,1e-268,1e-267,1e-266,1e-265,1e-264,1e-263,1e-262,1e-261,1e-260,
17 | 1e-259,1e-258,1e-257,1e-256,1e-255,1e-254,1e-253,1e-252,1e-251,1e-250,1e-249,1e-248,1e-247,1e-246,1e-245,1e-244,1e-243,1e-242,1e-241,1e-240,
18 | 1e-239,1e-238,1e-237,1e-236,1e-235,1e-234,1e-233,1e-232,1e-231,1e-230,1e-229,1e-228,1e-227,1e-226,1e-225,1e-224,1e-223,1e-222,1e-221,1e-220,
19 | 1e-219,1e-218,1e-217,1e-216,1e-215,1e-214,1e-213,1e-212,1e-211,1e-210,1e-209,1e-208,1e-207,1e-206,1e-205,1e-204,1e-203,1e-202,1e-201,1e-200,
20 | 1e-199,1e-198,1e-197,1e-196,1e-195,1e-194,1e-193,1e-192,1e-191,1e-190,1e-189,1e-188,1e-187,1e-186,1e-185,1e-184,1e-183,1e-182,1e-181,1e-180,
21 | 1e-179,1e-178,1e-177,1e-176,1e-175,1e-174,1e-173,1e-172,1e-171,1e-170,1e-169,1e-168,1e-167,1e-166,1e-165,1e-164,1e-163,1e-162,1e-161,1e-160,
22 | 1e-159,1e-158,1e-157,1e-156,1e-155,1e-154,1e-153,1e-152,1e-151,1e-150,1e-149,1e-148,1e-147,1e-146,1e-145,1e-144,1e-143,1e-142,1e-141,1e-140,
23 | 1e-139,1e-138,1e-137,1e-136,1e-135,1e-134,1e-133,1e-132,1e-131,1e-130,1e-129,1e-128,1e-127,1e-126,1e-125,1e-124,1e-123,1e-122,1e-121,1e-120,
24 | 1e-119,1e-118,1e-117,1e-116,1e-115,1e-114,1e-113,1e-112,1e-111,1e-110,1e-109,1e-108,1e-107,1e-106,1e-105,1e-104,1e-103,1e-102,1e-101,1e-100,
25 | 1e-99, 1e-98, 1e-97, 1e-96, 1e-95, 1e-94, 1e-93, 1e-92, 1e-91, 1e-90, 1e-89, 1e-88, 1e-87, 1e-86, 1e-85, 1e-84, 1e-83, 1e-82, 1e-81, 1e-80,
26 | 1e-79, 1e-78, 1e-77, 1e-76, 1e-75, 1e-74, 1e-73, 1e-72, 1e-71, 1e-70, 1e-69, 1e-68, 1e-67, 1e-66, 1e-65, 1e-64, 1e-63, 1e-62, 1e-61, 1e-60,
27 | 1e-59, 1e-58, 1e-57, 1e-56, 1e-55, 1e-54, 1e-53, 1e-52, 1e-51, 1e-50, 1e-49, 1e-48, 1e-47, 1e-46, 1e-45, 1e-44, 1e-43, 1e-42, 1e-41, 1e-40,
28 | 1e-39, 1e-38, 1e-37, 1e-36, 1e-35, 1e-34, 1e-33, 1e-32, 1e-31, 1e-30, 1e-29, 1e-28, 1e-27, 1e-26, 1e-25, 1e-24, 1e-23, 1e-22, 1e-21, 1e-20,
29 | 1e-19, 1e-18, 1e-17, 1e-16, 1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, 1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, 1e+0,
30 | 1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
31 | 1e+21, 1e+22, 1e+23, 1e+24, 1e+25, 1e+26, 1e+27, 1e+28, 1e+29, 1e+30, 1e+31, 1e+32, 1e+33, 1e+34, 1e+35, 1e+36, 1e+37, 1e+38, 1e+39, 1e+40,
32 | 1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
33 | 1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
34 | 1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
35 | 1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
36 | 1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
37 | 1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
38 | 1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
39 | 1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
40 | 1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
41 | 1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
42 | 1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
43 | 1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
44 | 1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
45 | 1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
46 | };
47 | RAPIDJSON_ASSERT(n <= 308);
48 | return n < -308 ? 0.0 : e[n + 308];
49 | }
50 |
51 | } // namespace internal
52 | } // namespace rapidjson
53 |
54 | #endif // RAPIDJSON_POW10_
55 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/internal/stack.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_INTERNAL_STACK_H_
2 | #define RAPIDJSON_INTERNAL_STACK_H_
3 |
4 | namespace rapidjson {
5 | namespace internal {
6 |
7 | ///////////////////////////////////////////////////////////////////////////////
8 | // Stack
9 |
10 | //! A type-unsafe stack for storing different types of data.
11 | /*! \tparam Allocator Allocator for allocating stack memory.
12 | */
13 | template
14 | class Stack {
15 | public:
16 | Stack(Allocator* allocator, size_t stack_capacity) : allocator_(allocator), own_allocator_(0), stack_(0), stack_top_(0), stack_end_(0), stack_capacity_(stack_capacity) {
17 | RAPIDJSON_ASSERT(stack_capacity_ > 0);
18 | if (!allocator_)
19 | own_allocator_ = allocator_ = new Allocator();
20 | stack_top_ = stack_ = (char*)allocator_->Malloc(stack_capacity_);
21 | stack_end_ = stack_ + stack_capacity_;
22 | }
23 |
24 | ~Stack() {
25 | Allocator::Free(stack_);
26 | delete own_allocator_; // Only delete if it is owned by the stack
27 | }
28 |
29 | void Clear() { /*stack_top_ = 0;*/ stack_top_ = stack_; }
30 |
31 | template
32 | T* Push(size_t count = 1) {
33 | // Expand the stack if needed
34 | if (stack_top_ + sizeof(T) * count >= stack_end_) {
35 | size_t new_capacity = stack_capacity_ * 2;
36 | size_t size = GetSize();
37 | size_t new_size = GetSize() + sizeof(T) * count;
38 | if (new_capacity < new_size)
39 | new_capacity = new_size;
40 | stack_ = (char*)allocator_->Realloc(stack_, stack_capacity_, new_capacity);
41 | stack_capacity_ = new_capacity;
42 | stack_top_ = stack_ + size;
43 | stack_end_ = stack_ + stack_capacity_;
44 | }
45 | T* ret = (T*)stack_top_;
46 | stack_top_ += sizeof(T) * count;
47 | return ret;
48 | }
49 |
50 | template
51 | T* Pop(size_t count) {
52 | RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
53 | stack_top_ -= count * sizeof(T);
54 | return (T*)stack_top_;
55 | }
56 |
57 | template
58 | T* Top() {
59 | RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
60 | return (T*)(stack_top_ - sizeof(T));
61 | }
62 |
63 | template
64 | T* Bottom() { return (T*)stack_; }
65 |
66 | Allocator& GetAllocator() { return *allocator_; }
67 | size_t GetSize() const { return stack_top_ - stack_; }
68 | size_t GetCapacity() const { return stack_capacity_; }
69 |
70 | private:
71 | Allocator* allocator_;
72 | Allocator* own_allocator_;
73 | char *stack_;
74 | char *stack_top_;
75 | char *stack_end_;
76 | size_t stack_capacity_;
77 | };
78 |
79 | } // namespace internal
80 | } // namespace rapidjson
81 |
82 | #endif // RAPIDJSON_STACK_H_
83 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/internal/strfunc.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_INTERNAL_STRFUNC_H_
2 | #define RAPIDJSON_INTERNAL_STRFUNC_H_
3 |
4 | namespace rapidjson {
5 | namespace internal {
6 |
7 | //! Custom strlen() which works on different character types.
8 | /*! \tparam Ch Character type (e.g. char, wchar_t, short)
9 | \param s Null-terminated input string.
10 | \return Number of characters in the string.
11 | \note This has the same semantics as strlen(), the return value is not number of Unicode codepoints.
12 | */
13 | template
14 | inline SizeType StrLen(const Ch* s) {
15 | const Ch* p = s;
16 | while (*p != '\0')
17 | ++p;
18 | return SizeType(p - s);
19 | }
20 |
21 | } // namespace internal
22 | } // namespace rapidjson
23 |
24 | #endif // RAPIDJSON_INTERNAL_STRFUNC_H_
25 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/prettywriter.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_PRETTYWRITER_H_
2 | #define RAPIDJSON_PRETTYWRITER_H_
3 |
4 | #include "writer.h"
5 |
6 | namespace rapidjson {
7 |
8 | //! Writer with indentation and spacing.
9 | /*!
10 | \tparam Stream Type of ouptut stream.
11 | \tparam Encoding Encoding of both source strings and output.
12 | \tparam Allocator Type of allocator for allocating memory of stack.
13 | */
14 | template, typename Allocator = MemoryPoolAllocator<> >
15 | class PrettyWriter : public Writer {
16 | public:
17 | typedef Writer Base;
18 | typedef typename Base::Ch Ch;
19 |
20 | //! Constructor
21 | /*! \param stream Output stream.
22 | \param allocator User supplied allocator. If it is null, it will create a private one.
23 | \param levelDepth Initial capacity of
24 | */
25 | PrettyWriter(Stream& stream, Allocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
26 | Base(stream, allocator, levelDepth), indentChar_(' '), indentCharCount_(4) {}
27 |
28 | //! Set custom indentation.
29 | /*! \param indentChar Character for indentation. Must be whitespace character (' ', '\t', '\n', '\r').
30 | \param indentCharCount Number of indent characters for each indentation level.
31 | \note The default indentation is 4 spaces.
32 | */
33 | PrettyWriter& SetIndent(Ch indentChar, unsigned indentCharCount) {
34 | RAPIDJSON_ASSERT(indentChar == ' ' || indentChar == '\t' || indentChar == '\n' || indentChar == '\r');
35 | indentChar_ = indentChar;
36 | indentCharCount_ = indentCharCount;
37 | return *this;
38 | }
39 |
40 | //@name Implementation of Handler.
41 | //@{
42 |
43 | PrettyWriter& Null() { PrettyPrefix(kNullType); Base::WriteNull(); return *this; }
44 | PrettyWriter& Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); Base::WriteBool(b); return *this; }
45 | PrettyWriter& Int(int i) { PrettyPrefix(kNumberType); Base::WriteInt(i); return *this; }
46 | PrettyWriter& Uint(unsigned u) { PrettyPrefix(kNumberType); Base::WriteUint(u); return *this; }
47 | PrettyWriter& Int64(int64_t i64) { PrettyPrefix(kNumberType); Base::WriteInt64(i64); return *this; }
48 | PrettyWriter& Uint64(uint64_t u64) { PrettyPrefix(kNumberType); Base::WriteUint64(u64); return *this; }
49 | PrettyWriter& Double(double d) { PrettyPrefix(kNumberType); Base::WriteDouble(d); return *this; }
50 |
51 | PrettyWriter& String(const Ch* str, SizeType length, bool copy = false) {
52 | (void)copy;
53 | PrettyPrefix(kStringType);
54 | Base::WriteString(str, length);
55 | return *this;
56 | }
57 |
58 | PrettyWriter& StartObject() {
59 | PrettyPrefix(kObjectType);
60 | new (Base::level_stack_.template Push()) typename Base::Level(false);
61 | Base::WriteStartObject();
62 | return *this;
63 | }
64 |
65 | PrettyWriter& EndObject(SizeType memberCount = 0) {
66 | (void)memberCount;
67 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
68 | RAPIDJSON_ASSERT(!Base::level_stack_.template Top()->inArray);
69 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0;
70 |
71 | if (!empty) {
72 | Base::stream_.Put('\n');
73 | WriteIndent();
74 | }
75 | Base::WriteEndObject();
76 | return *this;
77 | }
78 |
79 | PrettyWriter& StartArray() {
80 | PrettyPrefix(kArrayType);
81 | new (Base::level_stack_.template Push()) typename Base::Level(true);
82 | Base::WriteStartArray();
83 | return *this;
84 | }
85 |
86 | PrettyWriter& EndArray(SizeType memberCount = 0) {
87 | (void)memberCount;
88 | RAPIDJSON_ASSERT(Base::level_stack_.GetSize() >= sizeof(typename Base::Level));
89 | RAPIDJSON_ASSERT(Base::level_stack_.template Top()->inArray);
90 | bool empty = Base::level_stack_.template Pop(1)->valueCount == 0;
91 |
92 | if (!empty) {
93 | Base::stream_.Put('\n');
94 | WriteIndent();
95 | }
96 | Base::WriteEndArray();
97 | return *this;
98 | }
99 |
100 | //@}
101 |
102 | //! Simpler but slower overload.
103 | PrettyWriter& String(const Ch* str) { return String(str, internal::StrLen(str)); }
104 |
105 | protected:
106 | void PrettyPrefix(Type type) {
107 | (void)type;
108 | if (Base::level_stack_.GetSize() != 0) { // this value is not at root
109 | typename Base::Level* level = Base::level_stack_.template Top();
110 |
111 | if (level->inArray) {
112 | if (level->valueCount > 0) {
113 | Base::stream_.Put(','); // add comma if it is not the first element in array
114 | Base::stream_.Put('\n');
115 | }
116 | else
117 | Base::stream_.Put('\n');
118 | WriteIndent();
119 | }
120 | else { // in object
121 | if (level->valueCount > 0) {
122 | if (level->valueCount % 2 == 0) {
123 | Base::stream_.Put(',');
124 | Base::stream_.Put('\n');
125 | }
126 | else {
127 | Base::stream_.Put(':');
128 | Base::stream_.Put(' ');
129 | }
130 | }
131 | else
132 | Base::stream_.Put('\n');
133 |
134 | if (level->valueCount % 2 == 0)
135 | WriteIndent();
136 | }
137 | if (!level->inArray && level->valueCount % 2 == 0)
138 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
139 | level->valueCount++;
140 | }
141 | else
142 | RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
143 | }
144 |
145 | void WriteIndent() {
146 | size_t count = (Base::level_stack_.GetSize() / sizeof(typename Base::Level)) * indentCharCount_;
147 | PutN(Base::stream_, indentChar_, count);
148 | }
149 |
150 | Ch indentChar_;
151 | unsigned indentCharCount_;
152 | };
153 |
154 | } // namespace rapidjson
155 |
156 | #endif // RAPIDJSON_RAPIDJSON_H_
157 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/stringbuffer.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_STRINGBUFFER_H_
2 | #define RAPIDJSON_STRINGBUFFER_H_
3 |
4 | #include "rapidjson.h"
5 | #include "internal/stack.h"
6 |
7 | namespace rapidjson {
8 |
9 | //! Represents an in-memory output stream.
10 | /*!
11 | \tparam Encoding Encoding of the stream.
12 | \tparam Allocator type for allocating memory buffer.
13 | \implements Stream
14 | */
15 | template
16 | struct GenericStringBuffer {
17 | typedef typename Encoding::Ch Ch;
18 |
19 | GenericStringBuffer(Allocator* allocator = 0, size_t capacity = kDefaultCapacity) : stack_(allocator, capacity) {}
20 |
21 | void Put(Ch c) { *stack_.template Push() = c; }
22 |
23 | void Clear() { stack_.Clear(); }
24 |
25 | const char* GetString() const {
26 | // Push and pop a null terminator. This is safe.
27 | *stack_.template Push() = '\0';
28 | stack_.template Pop(1);
29 |
30 | return stack_.template Bottom();
31 | }
32 |
33 | size_t Size() const { return stack_.GetSize(); }
34 |
35 | static const size_t kDefaultCapacity = 256;
36 | mutable internal::Stack stack_;
37 | };
38 |
39 | typedef GenericStringBuffer > StringBuffer;
40 |
41 | //! Implement specialized version of PutN() with memset() for better performance.
42 | template<>
43 | inline void PutN(GenericStringBuffer >& stream, char c, size_t n) {
44 | memset(stream.stack_.Push(n), c, n * sizeof(c));
45 | }
46 |
47 | } // namespace rapidjson
48 |
49 | #endif // RAPIDJSON_STRINGBUFFER_H_
50 |
--------------------------------------------------------------------------------
/Libs/rapidjson/include/rapidjson/writer.h:
--------------------------------------------------------------------------------
1 | #ifndef RAPIDJSON_WRITER_H_
2 | #define RAPIDJSON_WRITER_H_
3 |
4 | #include "rapidjson.h"
5 | #include "internal/stack.h"
6 | #include "internal/strfunc.h"
7 | #include // snprintf() or _sprintf_s()
8 | #include // placement new
9 |
10 | #ifdef _MSC_VER
11 | #pragma warning(push)
12 | #pragma warning(disable : 4127) // conditional expression is constant
13 | #endif
14 |
15 | namespace rapidjson {
16 |
17 | //! JSON writer
18 | /*! Writer implements the concept Handler.
19 | It generates JSON text by events to an output stream.
20 |
21 | User may programmatically calls the functions of a writer to generate JSON text.
22 |
23 | On the other side, a writer can also be passed to objects that generates events,
24 |
25 | for example Reader::Parse() and Document::Accept().
26 |
27 | \tparam Stream Type of ouptut stream.
28 | \tparam Encoding Encoding of both source strings and output.
29 | \implements Handler
30 | */
31 | template, typename Allocator = MemoryPoolAllocator<> >
32 | class Writer {
33 | public:
34 | typedef typename Encoding::Ch Ch;
35 |
36 | Writer(Stream& stream, Allocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
37 | stream_(stream), level_stack_(allocator, levelDepth * sizeof(Level)) {}
38 |
39 | //@name Implementation of Handler
40 | //@{
41 | Writer& Null() { Prefix(kNullType); WriteNull(); return *this; }
42 | Writer& Bool(bool b) { Prefix(b ? kTrueType : kFalseType); WriteBool(b); return *this; }
43 | Writer& Int(int i) { Prefix(kNumberType); WriteInt(i); return *this; }
44 | Writer& Uint(unsigned u) { Prefix(kNumberType); WriteUint(u); return *this; }
45 | Writer& Int64(int64_t i64) { Prefix(kNumberType); WriteInt64(i64); return *this; }
46 | Writer& Uint64(uint64_t u64) { Prefix(kNumberType); WriteUint64(u64); return *this; }
47 | Writer& Double(double d) { Prefix(kNumberType); WriteDouble(d); return *this; }
48 |
49 | Writer& String(const Ch* str, SizeType length, bool copy = false) {
50 | (void)copy;
51 | Prefix(kStringType);
52 | WriteString(str, length);
53 | return *this;
54 | }
55 |
56 | Writer& StartObject() {
57 | Prefix(kObjectType);
58 | new (level_stack_.template Push()) Level(false);
59 | WriteStartObject();
60 | return *this;
61 | }
62 |
63 | Writer& EndObject(SizeType memberCount = 0) {
64 | (void)memberCount;
65 | RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
66 | RAPIDJSON_ASSERT(!level_stack_.template Top()->inArray);
67 | level_stack_.template Pop(1);
68 | WriteEndObject();
69 | return *this;
70 | }
71 |
72 | Writer& StartArray() {
73 | Prefix(kArrayType);
74 | new (level_stack_.template Push()) Level(true);
75 | WriteStartArray();
76 | return *this;
77 | }
78 |
79 | Writer& EndArray(SizeType elementCount = 0) {
80 | (void)elementCount;
81 | RAPIDJSON_ASSERT(level_stack_.GetSize() >= sizeof(Level));
82 | RAPIDJSON_ASSERT(level_stack_.template Top()->inArray);
83 | level_stack_.template Pop(1);
84 | WriteEndArray();
85 | return *this;
86 | }
87 | //@}
88 |
89 | //! Simpler but slower overload.
90 | Writer& String(const Ch* str) { return String(str, internal::StrLen(str)); }
91 |
92 | protected:
93 | //! Information for each nested level
94 | struct Level {
95 | Level(bool inArray_) : inArray(inArray_), valueCount(0) {}
96 | bool inArray; //!< true if in array, otherwise in object
97 | size_t valueCount; //!< number of values in this level
98 | };
99 |
100 | static const size_t kDefaultLevelDepth = 32;
101 |
102 | void WriteNull() {
103 | stream_.Put('n'); stream_.Put('u'); stream_.Put('l'); stream_.Put('l');
104 | }
105 |
106 | void WriteBool(bool b) {
107 | if (b) {
108 | stream_.Put('t'); stream_.Put('r'); stream_.Put('u'); stream_.Put('e');
109 | }
110 | else {
111 | stream_.Put('f'); stream_.Put('a'); stream_.Put('l'); stream_.Put('s'); stream_.Put('e');
112 | }
113 | }
114 |
115 | void WriteInt(int i) {
116 | if (i < 0) {
117 | stream_.Put('-');
118 | i = -i;
119 | }
120 | WriteUint((unsigned)i);
121 | }
122 |
123 | void WriteUint(unsigned u) {
124 | char buffer[10];
125 | char *p = buffer;
126 | do {
127 | *p++ = (u % 10) + '0';
128 | u /= 10;
129 | } while (u > 0);
130 |
131 | do {
132 | --p;
133 | stream_.Put(*p);
134 | } while (p != buffer);
135 | }
136 |
137 | void WriteInt64(int64_t i64) {
138 | if (i64 < 0) {
139 | stream_.Put('-');
140 | i64 = -i64;
141 | }
142 | WriteUint64((uint64_t)i64);
143 | }
144 |
145 | void WriteUint64(uint64_t u64) {
146 | char buffer[20];
147 | char *p = buffer;
148 | do {
149 | *p++ = char(u64 % 10) + '0';
150 | u64 /= 10;
151 | } while (u64 > 0);
152 |
153 | do {
154 | --p;
155 | stream_.Put(*p);
156 | } while (p != buffer);
157 | }
158 |
159 | //! \todo Optimization with custom double-to-string converter.
160 | void WriteDouble(double d) {
161 | char buffer[100];
162 | #if _MSC_VER
163 | int ret = sprintf_s(buffer, sizeof(buffer), "%g", d);
164 | #else
165 | int ret = snprintf(buffer, sizeof(buffer), "%g", d);
166 | #endif
167 | RAPIDJSON_ASSERT(ret >= 1);
168 | for (int i = 0; i < ret; i++)
169 | stream_.Put(buffer[i]);
170 | }
171 |
172 | void WriteString(const Ch* str, SizeType length) {
173 | static const char hexDigits[] = "0123456789ABCDEF";
174 | static const char escape[256] = {
175 | #define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
176 | //0 1 2 3 4 5 6 7 8 9 A B C D E F
177 | 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
178 | 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
179 | 0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
180 | Z16, Z16, // 30~4F
181 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
182 | Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
183 | #undef Z16
184 | };
185 |
186 | stream_.Put('\"');
187 | for (const Ch* p = str; p != str + length; ++p) {
188 | if ((sizeof(Ch) == 1 || *p < 256) && escape[(unsigned char)*p]) {
189 | stream_.Put('\\');
190 | stream_.Put(escape[(unsigned char)*p]);
191 | if (escape[(unsigned char)*p] == 'u') {
192 | stream_.Put('0');
193 | stream_.Put('0');
194 | stream_.Put(hexDigits[(*p) >> 4]);
195 | stream_.Put(hexDigits[(*p) & 0xF]);
196 | }
197 | }
198 | else
199 | stream_.Put(*p);
200 | }
201 | stream_.Put('\"');
202 | }
203 |
204 | void WriteStartObject() { stream_.Put('{'); }
205 | void WriteEndObject() { stream_.Put('}'); }
206 | void WriteStartArray() { stream_.Put('['); }
207 | void WriteEndArray() { stream_.Put(']'); }
208 |
209 | void Prefix(Type type) {
210 | (void)type;
211 | if (level_stack_.GetSize() != 0) { // this value is not at root
212 | Level* level = level_stack_.template Top();
213 | if (level->valueCount > 0) {
214 | if (level->inArray)
215 | stream_.Put(','); // add comma if it is not the first element in array
216 | else // in object
217 | stream_.Put((level->valueCount % 2 == 0) ? ',' : ':');
218 | }
219 | if (!level->inArray && level->valueCount % 2 == 0)
220 | RAPIDJSON_ASSERT(type == kStringType); // if it's in object, then even number should be a name
221 | level->valueCount++;
222 | }
223 | else
224 | RAPIDJSON_ASSERT(type == kObjectType || type == kArrayType);
225 | }
226 |
227 | Stream& stream_;
228 | internal::Stack level_stack_;
229 |
230 | private:
231 | // Prohibit assignment for VC C4512 warning
232 | Writer& operator=(const Writer& w);
233 | };
234 |
235 | } // namespace rapidjson
236 |
237 | #ifdef _MSC_VER
238 | #pragma warning(pop)
239 | #endif
240 |
241 | #endif // RAPIDJSON_RAPIDJSON_H_
242 |
--------------------------------------------------------------------------------
/MacCpp/.externalToolBuilders/Javah_jni_builder.launch:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/MacCpp/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 |
3 | #include "cocos2d.h"
4 | #include "SimpleAudioEngine.h"
5 | #include "cocos-ext.h"
6 |
7 | #include "HelloWorldScene.h"
8 | #include "LevelView.h"
9 |
10 | USING_NS_CC;
11 | using namespace CocosDenshion;
12 |
13 | AppDelegate::AppDelegate()
14 | {
15 | }
16 |
17 | AppDelegate::~AppDelegate()
18 | {
19 |
20 | }
21 |
22 | bool AppDelegate::applicationDidFinishLaunching()
23 | {
24 |
25 | // initialize director
26 | CCDirector *pDirector = CCDirector::sharedDirector();
27 | pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
28 |
29 | // CCScene * pScene = HelloWorld::scene();
30 | CCScene* pScene = LevelView::scene();
31 | pDirector->runWithScene(pScene);
32 |
33 | pDirector->setDisplayStats(true);
34 |
35 | return true;
36 | }
37 |
38 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
39 | void AppDelegate::applicationDidEnterBackground()
40 | {
41 | CCDirector::sharedDirector()->stopAnimation();
42 | SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
43 | SimpleAudioEngine::sharedEngine()->pauseAllEffects();
44 | }
45 |
46 | // this function will be called when the app is active again
47 | void AppDelegate::applicationWillEnterForeground()
48 | {
49 | CCDirector::sharedDirector()->startAnimation();
50 | SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
51 | SimpleAudioEngine::sharedEngine()->resumeAllEffects();
52 | }
53 |
--------------------------------------------------------------------------------
/MacCpp/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "cocos2d.h"
5 |
6 | /**
7 | @brief The cocos2d Application.
8 |
9 | The reason for implement as private inheritance is to hide some interface call by CCDirector.
10 | */
11 | class AppDelegate : private cocos2d::CCApplication
12 | {
13 | public:
14 | AppDelegate();
15 | virtual ~AppDelegate();
16 |
17 | /**
18 | @brief Implement CCDirector and CCScene init code here.
19 | @return true Initialize success, app continue.
20 | @return false Initialize failed, app terminate.
21 | */
22 | virtual bool applicationDidFinishLaunching();
23 |
24 | /**
25 | @brief The function be called when the application enter background
26 | @param the pointer of the application
27 | */
28 | virtual void applicationDidEnterBackground();
29 |
30 | /**
31 | @brief The function be called when the application enter foreground
32 | @param the pointer of the application
33 | */
34 | virtual void applicationWillEnterForeground();
35 | };
36 |
37 | #endif // _APP_DELEGATE_H_
38 |
39 |
--------------------------------------------------------------------------------
/MacCpp/Classes/HelloWorldScene.cpp:
--------------------------------------------------------------------------------
1 | #include "HelloWorldScene.h"
2 | #include "SimpleAudioEngine.h"
3 |
4 | using namespace cocos2d;
5 | using namespace CocosDenshion;
6 |
7 | CCScene* HelloWorld::scene()
8 | {
9 | // 'scene' is an autorelease object
10 | CCScene *scene = CCScene::create();
11 |
12 | // 'layer' is an autorelease object
13 | HelloWorld *layer = HelloWorld::create();
14 |
15 | // add layer as a child to scene
16 | scene->addChild(layer);
17 |
18 | // return the scene
19 | return scene;
20 | }
21 |
22 | // on "init" you need to initialize your instance
23 | bool HelloWorld::init()
24 | {
25 | //////////////////////////////
26 | // 1. super init first
27 | if ( !CCLayer::init() )
28 | {
29 | return false;
30 | }
31 |
32 | /////////////////////////////
33 | // 2. add a menu item with "X" image, which is clicked to quit the program
34 | // you may modify it.
35 |
36 | // add a "close" icon to exit the progress. it's an autorelease object
37 | CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
38 | "CloseNormal.png",
39 | "CloseSelected.png",
40 | this,
41 | menu_selector(HelloWorld::menuCloseCallback) );
42 | pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
43 |
44 | // create menu, it's an autorelease object
45 | CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
46 | pMenu->setPosition( CCPointZero );
47 | this->addChild(pMenu, 1);
48 |
49 | /////////////////////////////
50 | // 3. add your codes below...
51 |
52 | // add a label shows "Hello World"
53 | // create and initialize a label
54 | CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
55 |
56 | // ask director the window size
57 | CCSize size = CCDirector::sharedDirector()->getWinSize();
58 |
59 | // position the label on the center of the screen
60 | pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
61 |
62 | // add the label as a child to this layer
63 | this->addChild(pLabel, 1);
64 |
65 | // add "HelloWorld" splash screen"
66 | CCSprite* pSprite = CCSprite::create("HelloWorld.png");
67 |
68 | // position the sprite on the center of the screen
69 | pSprite->setPosition( ccp(size.width/2, size.height/2) );
70 |
71 | // add the sprite as a child to this layer
72 | this->addChild(pSprite, 0);
73 |
74 | return true;
75 | }
76 |
77 | void HelloWorld::menuCloseCallback(CCObject* pSender)
78 | {
79 | CCDirector::sharedDirector()->end();
80 |
81 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
82 | exit(0);
83 | #endif
84 | }
85 |
--------------------------------------------------------------------------------
/MacCpp/Classes/HelloWorldScene.h:
--------------------------------------------------------------------------------
1 | #ifndef __HELLOWORLD_SCENE_H__
2 | #define __HELLOWORLD_SCENE_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | class HelloWorld : public cocos2d::CCLayer
7 | {
8 | public:
9 | // Method 'init' in cocos2d-x returns bool, instead of 'id' in cocos2d-iphone (an object pointer)
10 | virtual bool init();
11 |
12 | // there's no 'id' in cpp, so we recommend to return the class instance pointer
13 | static cocos2d::CCScene* scene();
14 |
15 | // a selector callback
16 | void menuCloseCallback(CCObject* pSender);
17 |
18 | // preprocessor macro for "static create()" constructor ( node() deprecated )
19 | CREATE_FUNC(HelloWorld);
20 | };
21 |
22 | #endif // __HELLOWORLD_SCENE_H__
23 |
--------------------------------------------------------------------------------
/MacCpp/Classes/LevelView.h:
--------------------------------------------------------------------------------
1 | //
2 | // LevelView.h
3 | // Map
4 | //
5 | // Created by leafsoar on 7/27/13.
6 | //
7 | //
8 |
9 | #ifndef Map_LevelView_h
10 | #define Map_LevelView_h
11 |
12 | #include "cocos2d.h"
13 | #include "cocos-ext.h"
14 |
15 | #include "LsTouch.h"
16 |
17 | USING_NS_CC;
18 | USING_NS_CC_EXT;
19 |
20 | class LevelView: public CCLayer, LsTouchEvent{
21 | public:
22 | LevelView();
23 | ~LevelView();
24 |
25 | static CCScene* scene();
26 | virtual bool init();
27 | CREATE_FUNC(LevelView);
28 |
29 | virtual void touchEventAction(LsTouch* touch, int type);
30 |
31 | virtual void registerWithTouchDispatcher(void);
32 |
33 | virtual bool ccTouchBegan(CCTouch* pTouch, CCEvent* pEvent);
34 | virtual void ccTouchMoved(CCTouch* pTouch, CCEvent* pEvent);
35 | virtual void ccTouchEnded(CCTouch* pTouch, CCEvent* pEvent);
36 | virtual void ccTouchCancelled(CCTouch* pTouch, CCEvent* pEvent);
37 |
38 | void adjustScrollView(float offset);
39 | CCLayer* getContainLayer();
40 |
41 | CCNode* getSpriteByLevel(int level);
42 |
43 | void setCurPageBall();
44 |
45 |
46 | private:
47 | CCPoint m_touchPoint;
48 | CCPoint m_touchOffset;
49 |
50 | int m_nCurPage;
51 | int m_nPageCount;
52 |
53 | CC_SYNTHESIZE_RETAIN(CCScrollView*, m_pScrollView, ScrollView);
54 | };
55 |
56 | #endif
57 |
--------------------------------------------------------------------------------
/MacCpp/Classes/LsTouch.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | * LsTouch.cpp
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #include "LsTouch.h"
9 |
10 | LsTouch::LsTouch() {
11 | CCLog("LsTouch()");
12 | m_iEventId = 0;
13 | }
14 |
15 | LsTouch::~LsTouch() {
16 | CCLog("LsTouch().~()");
17 | }
18 |
19 | bool LsTouch::init() {
20 |
21 | return true;
22 | }
23 |
24 | void LsTouch::setDisplay(CCSprite* dis) {
25 | // 设置之前先清除,没有也无所谓
26 | removeChildByTag(TAG_DISPLAY, true);
27 | addChild(dis, 0, TAG_DISPLAY);
28 | }
29 |
30 | CCSprite* LsTouch::getDisplay(){
31 | return dynamic_cast(this->getChildByTag(TAG_DISPLAY));
32 | }
33 |
34 | void LsTouch::setEventId(int eventId) {
35 | m_iEventId = eventId;
36 | }
37 |
38 | int LsTouch::getEventId() {
39 | return m_iEventId;
40 | }
41 |
42 | bool LsTouch::selfCheck(CCTouch* ccTouch, LsTouchEvent* lsTe) {
43 | bool bRef = false;
44 | // 可点击项的检测,可扩展
45 | do {
46 | // 是否通过点击位置检测
47 | CC_BREAK_IF(!containsCCTouchPoint(ccTouch));
48 | // 是否正在运行,排除可能存在已经从界面移除,但是并没有释放的可能
49 | CC_BREAK_IF(!isRunning());
50 | // 判断是否隐藏
51 | CC_BREAK_IF(!isVisible());
52 | // 这里可能还需要判断内部显示项目是否隐藏
53 | ///// 暂留
54 | bRef = true;
55 | } while (0);
56 | return bRef;
57 | }
58 |
59 | bool LsTouch::containsCCTouchPoint(CCTouch* ccTouch) {
60 | // 获得显示内容
61 | CCNode* dis = getChildByTag(TAG_DISPLAY);
62 | CCSprite* sprite = dynamic_cast(dis);
63 | CCPoint point = sprite->convertTouchToNodeSpaceAR(ccTouch);
64 | CCSize s = sprite->getTexture()->getContentSize();
65 | CCRect rect = CCRectMake(-s.width / 2, -s.height / 2, s.width, s.height);
66 | return rect.containsPoint(point);
67 | }
68 |
69 | bool LsTouch::isParentAllVisible(LsTouchEvent* lsTe) {
70 | bool bRef = true;
71 | // 向父类转型,以便获取地址比较对象,LsTouchEvent 的对象必须同时直接或者简介继承 CCNode
72 | CCNode* nLsTe = dynamic_cast(lsTe);
73 |
74 | CCNode* parent = getParent();
75 | do {
76 | // 如果遍历完毕,说明 LsTouch 不再 LsTouchEvent 之内
77 | if (!parent) {
78 | bRef = false;
79 | break;
80 | }
81 | // 如果 LsTouch 在 LsTouchEvent 之内,返回 true
82 | // 注意:如果想让LsTouchEvent 处理 不在其 CCNode 结构之内的元素,则取消此处判断
83 | if (nLsTe == parent) {
84 | break;
85 | }
86 | if (!parent->isVisible()) {
87 | bRef = false;
88 | break;
89 | }
90 | parent = parent->getParent();
91 | } while (1);
92 | return bRef;
93 | }
94 |
95 | LsTouchEvent::LsTouchEvent() {
96 | CCLog("LsTouchEvent()");
97 | m_pLsTouches = CCArray::create();
98 | m_pLsTouches->retain();
99 | }
100 |
101 | LsTouchEvent::~LsTouchEvent() {
102 | CCLog("LsTouchEvent().~()");
103 | m_pLsTouches->release();
104 | }
105 |
106 | void LsTouchEvent::addLsTouch(LsTouch* touch, int eventId) {
107 | touch->setEventId(eventId);
108 | m_pLsTouches->addObject(touch);
109 | }
110 |
111 | void LsTouchEvent::removeLsTouch(LsTouch* touch) {
112 | m_pLsTouches->removeObject(touch, true);
113 | }
114 |
115 | bool LsTouchEvent::sendTouchMessage(CCTouch* ccTouch, int type) {
116 | // 编写判断,集合中的哪个元素级别高,就触发哪一个
117 | LsTouch* lsTouch = NULL;
118 | // 获得点击的点
119 | CCObject* pObj = NULL;
120 | LsTouch* lt = NULL;
121 | CCARRAY_FOREACH(m_pLsTouches, pObj) {
122 | lt = dynamic_cast(pObj);
123 | if (lt) {
124 | if (lt->selfCheck(ccTouch, this)) {
125 | if (lsTouch == NULL)
126 | lsTouch = lt;
127 | else
128 | // 如果已存在符合条件元素,比较优先级
129 | lsTouch = getPriorityTouch(lsTouch, lt);
130 | }
131 | }
132 | }
133 | // 返回 可以为空
134 | touchEventAction(lsTouch, type);
135 | return true;
136 | }
137 |
138 | LsTouch* LsTouchEvent::getPriorityTouch(LsTouch* a, LsTouch* b) {
139 | // 触摸优先级通过 CCNode 树判断,也既是显示层次级别等因素
140 | // 以当前元素为“根”向父类转型,以便获取地址比较对象,LsTouchEvent 的对象必须同时直接或者简介继承 CCNode
141 | CCNode* nLsTe = dynamic_cast(this);
142 |
143 | // 共同的分枝
144 | CCNode* allParent = NULL;
145 | // 寻找 a 与 b 共同的分枝
146 | CCNode* nAParent = a;
147 | CCNode* nBParent = b;
148 | CCNode* nAChild = NULL;
149 | CCNode* nBChild = NULL;
150 | do {
151 | nAChild = nAParent;
152 | nAParent = nAParent->getParent();
153 | if (!nAParent)
154 | break;
155 |
156 | nBParent = b;
157 | do {
158 | nBChild = nBParent;
159 | nBParent = nBParent->getParent();
160 | if (!nBParent)
161 | break;
162 | if (nAParent == nBParent) {
163 | allParent = nAParent;
164 | break;
165 | }
166 | if (nBParent == nLsTe) {
167 | break;
168 | }
169 | } while (1);
170 | if (allParent)
171 | break;
172 | if (nAParent == nLsTe) {
173 | break;
174 | }
175 | } while (1);
176 |
177 | // 此处只需要判断 nAChild 和 nBChild 的优先级即可,默认返回 a
178 | if (!nAChild || !nBChild)
179 | return a;
180 | // 根据 ZOrder 判断,如果 ZOrder一样,根据索引位置判断
181 | if (nAChild->getZOrder() == nBChild->getZOrder())
182 | return allParent->getChildren()->indexOfObject(nAChild) > allParent->getChildren()->indexOfObject(nBChild)? a: b;
183 | else
184 | return nAChild->getZOrder() > nBChild->getZOrder()? a: b;
185 | }
186 |
--------------------------------------------------------------------------------
/MacCpp/Classes/LsTouch.h:
--------------------------------------------------------------------------------
1 | /*
2 | * LsTouch.h
3 | *
4 | * Created on: May 24, 2013
5 | * Author: leafsoar
6 | */
7 |
8 | #ifndef LSTOUCH_H_
9 | #define LSTOUCH_H_
10 |
11 | #include "cocos2d.h"
12 |
13 | USING_NS_CC;
14 |
15 | class LsTouchEvent;
16 |
17 | /**
18 | * 定义可触摸元素,用于统一管理
19 | */
20 | class LsTouch: public CCNode {
21 | public:
22 | LsTouch();
23 | ~LsTouch();
24 | CREATE_FUNC(LsTouch);
25 | virtual bool init() ;
26 |
27 | // 设置显示项
28 | void setDisplay(CCSprite* dis);
29 | CCSprite* getDisplay();
30 |
31 | void setEventId(int eventId);
32 | int getEventId();
33 |
34 | /// 常规判断
35 | bool selfCheck(CCTouch* ccTouch, LsTouchEvent* lsTe);
36 |
37 | private:
38 | // 判断当前的元素是否被点击
39 | bool containsCCTouchPoint(CCTouch* ccTouch);
40 | bool isParentAllVisible(LsTouchEvent* lsTe);
41 |
42 | // 用户保存显示精灵的 tag
43 | static const int TAG_DISPLAY = 100;
44 | int m_iEventId;
45 |
46 | };
47 |
48 | class LsTouchEvent {
49 | public:
50 | LsTouchEvent();
51 | ~LsTouchEvent();
52 |
53 | void addLsTouch(LsTouch* touch, int eventId);
54 |
55 | void removeLsTouch(LsTouch* touch);
56 |
57 | bool sendTouchMessage(CCTouch* ccTouch, int type);
58 |
59 | // 返回优先级较高的可触摸对象
60 | LsTouch* getPriorityTouch(LsTouch* a, LsTouch* b);
61 |
62 | virtual void touchEventAction(LsTouch* touch, int type) = 0;
63 | private:
64 | CCArray* m_pLsTouches;
65 | };
66 |
67 | #endif /* LSTOUCH_H_ */
68 |
--------------------------------------------------------------------------------
/MacCpp/Classes/PopupLayer/PopupLayer.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // PopupLayer.cpp
3 | // TestCpp
4 | //
5 | // Created by leafsoar on 7/29/13.
6 | //
7 | //
8 |
9 | #include "PopupLayer.h"
10 |
11 | PopupLayer::PopupLayer():
12 | m__pMenu(NULL)
13 | , m_contentPadding(0)
14 | , m_contentPaddingTop(0)
15 | , m_callbackListener(NULL)
16 | , m_callback(NULL)
17 | , m__sfBackGround(NULL)
18 | , m__s9BackGround(NULL)
19 | , m__ltContentText(NULL)
20 | , m__ltTitle(NULL)
21 | {
22 |
23 | }
24 |
25 | PopupLayer::~PopupLayer(){
26 | CC_SAFE_RELEASE(m__pMenu);
27 | CC_SAFE_RELEASE(m__sfBackGround);
28 | CC_SAFE_RELEASE(m__ltContentText);
29 | CC_SAFE_RELEASE(m__ltTitle);
30 | CC_SAFE_RELEASE(m__s9BackGround);
31 | }
32 |
33 | bool PopupLayer::init(){
34 | bool bRef = false;
35 | do{
36 | CC_BREAK_IF(!CCLayer::init());
37 | this->setContentSize(CCSizeZero);
38 |
39 | // 初始化需要的 Menu
40 | CCMenu* menu = CCMenu::create();
41 | menu->setPosition(CCPointZero);
42 | setMenuButton(menu);
43 |
44 | setTouchEnabled(true);
45 |
46 | bRef = true;
47 | }while(0);
48 | return bRef;
49 | }
50 |
51 | void PopupLayer::registerWithTouchDispatcher(){
52 | // 这里的触摸优先级设置为 -128 这保证了,屏蔽下方的触摸
53 | CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, -128, true);
54 |
55 | }
56 |
57 | bool PopupLayer::ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent){
58 | //
59 | CCLog("PopupLayer touch");
60 | return true;
61 | }
62 |
63 | PopupLayer* PopupLayer::create(const char *backgroundImage){
64 | PopupLayer* ml = PopupLayer::create();
65 | ml->setSpriteBackGround(CCSprite::create(backgroundImage));
66 | ml->setSprite9BackGround(CCScale9Sprite::create(backgroundImage));
67 | return ml;
68 | }
69 |
70 | void PopupLayer::setTitle(const char *title, int fontsize){
71 | CCLabelTTF* ltfTitle = CCLabelTTF::create(title, "", fontsize);
72 | setLabelTitle(ltfTitle);
73 | }
74 |
75 | void PopupLayer::setContentText(const char *text, int fontsize, int padding, int paddingTop){
76 | CCLabelTTF* ltf = CCLabelTTF::create(text, "", fontsize);
77 | setLabelContentText(ltf);
78 | m_contentPadding = padding;
79 | m_contentPaddingTop = paddingTop;
80 | }
81 |
82 | void PopupLayer::setCallbackFunc(cocos2d::CCObject *target, SEL_CallFuncN callfun){
83 | m_callbackListener = target;
84 | m_callback = callfun;
85 | }
86 |
87 |
88 | bool PopupLayer::addButton(const char *normalImage, const char *selectedImage, const char *title, int tag){
89 | CCSize winSize = CCDirector::sharedDirector()->getWinSize();
90 | CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
91 |
92 | // 创建图片菜单按钮
93 | CCMenuItemImage* menuImage = CCMenuItemImage::create(normalImage, selectedImage, this, menu_selector(PopupLayer::buttonCallback));
94 | menuImage->setTag(tag);
95 | menuImage->setPosition(pCenter);
96 |
97 | // 添加文字说明并设置位置
98 | CCSize imenu = menuImage->getContentSize();
99 | CCLabelTTF* ttf = CCLabelTTF::create(title, "", 20);
100 | ttf->setColor(ccc3(0, 0, 0));
101 | ttf->setPosition(ccp(imenu.width / 2, imenu.height / 2));
102 | menuImage->addChild(ttf);
103 |
104 | getMenuButton()->addChild(menuImage);
105 | return true;
106 | }
107 |
108 | void PopupLayer::buttonCallback(cocos2d::CCObject *pSender){
109 | CCNode* node = dynamic_cast(pSender);
110 | CCLog("touch tag: %d", node->getTag());
111 | if (m_callback && m_callbackListener){
112 | (m_callbackListener->*m_callback)(node);
113 | }
114 | this->removeFromParent();
115 | }
116 |
117 | void PopupLayer::onEnter(){
118 | CCLayer::onEnter();
119 |
120 | CCSize winSize = CCDirector::sharedDirector()->getWinSize();
121 | CCPoint pCenter = ccp(winSize.width / 2, winSize.height / 2);
122 |
123 | CCSize contentSize;
124 | // 设定好参数,在运行时加载
125 | if (getContentSize().equals(CCSizeZero)) {
126 | getSpriteBackGround()->setPosition(ccp(winSize.width / 2, winSize.height / 2));
127 | this->addChild(getSpriteBackGround(), 0, 0);
128 | contentSize = getSpriteBackGround()->getTexture()->getContentSize();
129 | } else {
130 | CCScale9Sprite *background = getSprite9BackGround();
131 | background->setContentSize(getContentSize());
132 | background->setPosition(ccp(winSize.width / 2, winSize.height / 2));
133 | this->addChild(background, 0, 0);
134 | contentSize = getContentSize();
135 | }
136 |
137 |
138 | // 添加按钮,并设置其位置
139 | this->addChild(getMenuButton());
140 | float btnWidth = contentSize.width / (getMenuButton()->getChildrenCount() + 1);
141 |
142 | CCArray* array = getMenuButton()->getChildren();
143 | CCObject* pObj = NULL;
144 | int i = 0;
145 | CCARRAY_FOREACH(array, pObj){
146 | CCNode* node = dynamic_cast(pObj);
147 | node->setPosition(ccp( winSize.width / 2 - contentSize.width / 2 + btnWidth * (i + 1), winSize.height / 2 - contentSize.height / 3));
148 | i++;
149 | }
150 |
151 |
152 | // 显示对话框标题
153 | if (getLabelTitle()){
154 | getLabelTitle()->setPosition(ccpAdd(pCenter, ccp(0, contentSize.height / 2 - 35.0f)));
155 | this->addChild(getLabelTitle());
156 | }
157 |
158 | // 显示文本内容
159 | if (getLabelContentText()){
160 | CCLabelTTF* ltf = getLabelContentText();
161 | ltf->setPosition(ccp(winSize.width / 2, winSize.height / 2));
162 | ltf->setDimensions(CCSizeMake(contentSize.width - m_contentPadding * 2, contentSize.height - m_contentPaddingTop));
163 | ltf->setHorizontalAlignment(kCCTextAlignmentLeft);
164 | this->addChild(ltf);
165 | }
166 |
167 | // 弹出效果
168 | CCAction* popupLayer = CCSequence::create(CCScaleTo::create(0.0, 0.0),
169 | CCScaleTo::create(0.06, 1.05),
170 | CCScaleTo::create(0.08, 0.95),
171 | CCScaleTo::create(0.08, 1.0), NULL);
172 | this->runAction(popupLayer);
173 |
174 | }
175 |
176 | void PopupLayer::onExit(){
177 |
178 | CCLog("popup on exit.");
179 | CCLayer::onExit();
180 | }
181 |
--------------------------------------------------------------------------------
/MacCpp/Classes/PopupLayer/PopupLayer.h:
--------------------------------------------------------------------------------
1 | //
2 | // PopupLayer.h
3 | // TestCpp
4 | //
5 | // Created by leafsoar on 7/29/13.
6 | //
7 | //
8 |
9 | #ifndef TestCpp_PopupLayer_h
10 | #define TestCpp_PopupLayer_h
11 |
12 | #include "cocos2d.h"
13 | #include "cocos-ext.h"
14 |
15 | using namespace cocos2d;
16 | using namespace cocos2d::extension;
17 |
18 | class PopupLayer: public CCLayer{
19 | public:
20 | PopupLayer();
21 | ~PopupLayer();
22 |
23 | virtual bool init();
24 | CREATE_FUNC(PopupLayer);
25 |
26 | virtual void registerWithTouchDispatcher(void);
27 | bool ccTouchBegan(cocos2d::CCTouch *pTouch, cocos2d::CCEvent *pEvent);
28 |
29 | static PopupLayer* create(const char* backgroundImage);
30 |
31 | void setTitle(const char* title, int fontsize = 20);
32 | void setContentText(const char* text, int fontsize = 20, int padding = 50, int paddintTop = 100);
33 |
34 | void setCallbackFunc(CCObject* target, SEL_CallFuncN callfun);
35 |
36 | bool addButton(const char* normalImage, const char* selectedImage, const char* title, int tag = 0);
37 | virtual void onEnter();
38 | virtual void onExit();
39 |
40 | private:
41 |
42 | void buttonCallback(CCObject* pSender);
43 |
44 | // 文字内容两边的空白区
45 | int m_contentPadding;
46 | int m_contentPaddingTop;
47 |
48 | CCObject* m_callbackListener;
49 | SEL_CallFuncN m_callback;
50 |
51 | CC_SYNTHESIZE_RETAIN(CCMenu*, m__pMenu, MenuButton);
52 | CC_SYNTHESIZE_RETAIN(CCSprite*, m__sfBackGround, SpriteBackGround);
53 | CC_SYNTHESIZE_RETAIN(CCScale9Sprite*, m__s9BackGround, Sprite9BackGround);
54 | CC_SYNTHESIZE_RETAIN(CCLabelTTF*, m__ltTitle, LabelTitle);
55 | CC_SYNTHESIZE_RETAIN(CCLabelTTF*, m__ltContentText, LabelContentText);
56 |
57 |
58 | };
59 |
60 | #endif
61 |
--------------------------------------------------------------------------------
/MacCpp/Classes/PopupLayer/PopupScene.cpp:
--------------------------------------------------------------------------------
1 | //
2 | // PopupScene.cpp
3 | // TestCpp
4 | //
5 | // Created by leafsoar on 7/29/13.
6 | //
7 | //
8 |
9 | #include "PopupScene.h"
10 | #include "PopupLayer.h"
11 |
12 | CCScene* Popup::scene(){
13 | CCScene* scene = CCScene::create();
14 | CCLayer* layer = Popup::create();
15 | scene->addChild(layer);
16 | return scene;
17 | }
18 |
19 | bool Popup::init(){
20 | bool bRef = false;
21 |
22 | do {
23 | CC_BREAK_IF(!CCLayer::init());
24 |
25 | CCSize winSize = CCDirector::sharedDirector()->getWinSize();
26 | CCPoint pointCenter = ccp(winSize.width / 2, winSize.height / 2);
27 |
28 | // 添加背景图片
29 | CCSprite* background = CCSprite::create("HelloWorld.png");
30 | background->setPosition(pointCenter);
31 | background->setScale(1.5f);
32 | this->addChild(background);
33 |
34 | // popupLayer();
35 |
36 |
37 | // 添加菜单
38 | CCMenu* menu = CCMenu::create();
39 |
40 | CCMenuItemFont* menuItem = CCMenuItemFont::create("popup", this, menu_selector(Popup::menuCallback));
41 | menuItem->setPosition(ccp(200, 50));
42 | menuItem->setColor(ccc3(0, 0, 0));
43 | menu->addChild(menuItem);
44 |
45 |
46 | menu->setPosition(CCPointZero);
47 | this->addChild(menu);
48 |
49 |
50 | CCLog("klt");
51 | bRef = true;
52 | } while (0);
53 |
54 | return bRef;
55 | }
56 |
57 | void Popup::popupLayer(){
58 | // 定义一个弹出层,传入一张背景图
59 | PopupLayer* pl = PopupLayer::create("popuplayer/BackGround.png");
60 | // ContentSize 是可选的设置,可以不设置,如果设置把它当作 9 图缩放
61 | pl->setContentSize(CCSizeMake(400, 350));
62 | pl->setTitle("吾名一叶");
63 | pl->setContentText("娇兰傲梅世人赏,却少幽芬暗里藏。不看百花共争艳,独爱疏樱一枝香。", 20, 60, 250);
64 | // 设置回调函数,回调传回一个 CCNode 以获取 tag 判断点击的按钮
65 | // 这只是作为一种封装实现,如果使用 delegate 那就能够更灵活的控制参数了
66 | pl->setCallbackFunc(this, callfuncN_selector(Popup::buttonCallback));
67 | // 添加按钮,设置图片,文字,tag 信息
68 | pl->addButton("popuplayer/pop_button.png", "popuplayer/pop_button.png", "确定", 0);
69 | pl->addButton("popuplayer/pop_button.png", "popuplayer/pop_button.png", "取消", 1);
70 | // 添加到当前层
71 | this->addChild(pl);
72 | }
73 |
74 | void Popup::menuCallback(cocos2d::CCObject *pSender){
75 | popupLayer();
76 | }
77 |
78 | void Popup::buttonCallback(cocos2d::CCNode *pNode){
79 | CCLog("button call back. tag: %d", pNode->getTag());
80 | }
--------------------------------------------------------------------------------
/MacCpp/Classes/PopupLayer/PopupScene.h:
--------------------------------------------------------------------------------
1 | //
2 | // PopupScene.h
3 | // TestCpp
4 | //
5 | // Created by leafsoar on 7/29/13.
6 | //
7 | //
8 |
9 | #ifndef TestCpp_PopupScene_h
10 | #define TestCpp_PopupScene_h
11 |
12 | #include "cocos2d.h"
13 |
14 | USING_NS_CC;
15 |
16 | class Popup: public CCLayer{
17 | public:
18 | static CCScene* scene();
19 | virtual bool init();
20 | CREATE_FUNC(Popup);
21 |
22 | void popupLayer();
23 |
24 | void menuCallback(CCObject* pSender);
25 | void buttonCallback(CCNode* pSender);
26 | };
27 |
28 | #endif
29 |
--------------------------------------------------------------------------------
/MacCpp/Resources/.gitignore:
--------------------------------------------------------------------------------
1 | #Do now ignore Marmalade icf files
2 | !*.icf
3 |
--------------------------------------------------------------------------------
/MacCpp/Resources/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/CloseNormal.png
--------------------------------------------------------------------------------
/MacCpp/Resources/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/CloseSelected.png
--------------------------------------------------------------------------------
/MacCpp/Resources/CocosBuilderExample.ccbproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | deviceOrientationLandscapeLeft
6 |
7 | deviceOrientationLandscapeRight
8 |
9 | deviceOrientationPortrait
10 |
11 | deviceOrientationUpsideDown
12 |
13 | exporter
14 | ccbi
15 | fileType
16 | CocosBuilderProject
17 | fileVersion
18 | 1
19 | flattenPaths
20 |
21 | generatedSpriteSheets
22 |
23 | javascriptBased
24 |
25 | javascriptMainCCB
26 |
27 | onlyPublishCCBs
28 |
29 | publishDirectory
30 | .
31 | publishDirectoryAndroid
32 |
33 | publishDirectoryHTML5
34 |
35 | publishEnabledAndroid
36 |
37 | publishEnabledHTML5
38 |
39 | publishEnablediPhone
40 |
41 | publishResolutionHTML5_height
42 | 640
43 | publishResolutionHTML5_scale
44 | 2
45 | publishResolutionHTML5_width
46 | 960
47 | publishResolution_
48 |
49 | publishResolution_hd
50 |
51 | publishResolution_ipad
52 |
53 | publishResolution_ipadhd
54 |
55 | publishResolution_large
56 |
57 | publishResolution_medium
58 |
59 | publishResolution_small
60 |
61 | publishResolution_xlarge
62 |
63 | publishResolution_xsmall
64 |
65 | publishToZipFile
66 |
67 | resourceAutoScaleFactor
68 | 4
69 | resourcePaths
70 |
71 |
72 |
73 |
--------------------------------------------------------------------------------
/MacCpp/Resources/Default.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/Default.png
--------------------------------------------------------------------------------
/MacCpp/Resources/HelloWorld.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/HelloWorld.png
--------------------------------------------------------------------------------
/MacCpp/Resources/app.icf:
--------------------------------------------------------------------------------
1 | # This file is for configuration settings for your
2 | # application.
3 | #
4 | # The syntax is similar to windows .ini files ie
5 | #
6 | # [GroupName]
7 | # Setting = Value
8 | #
9 | # Which can be read by your application using
10 | # e.g s3eConfigGetString("GroupName", "Setting", string)
11 | #
12 | # All settings must be documented in .config.txt files.
13 | # New settings specific to this application should be
14 | # documented in app.config.txt
15 | #
16 | # Some conditional operations are also permitted, see the
17 | # S3E documentation for details.
18 | [S3E]
19 | MemSize = 100000000
20 | # Sample only compatible with 480x320 display resolution
21 | WinWidth=480
22 | WinHeight=320
23 |
24 | [GL]
25 | AllowNegativeUniformLocation=1
26 |
27 |
--------------------------------------------------------------------------------
/MacCpp/Resources/fileLookup.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | filenames
6 |
7 | metadata
8 |
9 | version
10 | 1
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/MacCpp/Resources/level/GameBackGround.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/GameBackGround.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/ball.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/ball.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/frame.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/frame.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/level.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/level.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/level_lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/level_lock.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/prim30.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/prim30.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/sel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/sel.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/star5.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/star5.png
--------------------------------------------------------------------------------
/MacCpp/Resources/level/star6.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/level/star6.png
--------------------------------------------------------------------------------
/MacCpp/Resources/popuplayer/BackGround.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/popuplayer/BackGround.png
--------------------------------------------------------------------------------
/MacCpp/Resources/popuplayer/pop_button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/Resources/popuplayer/pop_button.png
--------------------------------------------------------------------------------
/MacCpp/proj.mac/AppController.h:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | #pragma once
26 |
27 | #import "cocos2d.h"
28 | #import "EAGLView.h"
29 |
30 | @interface AppController : NSObject
31 | {
32 | NSWindow *window;
33 | EAGLView *glView;
34 | }
35 |
36 | @property (nonatomic, assign) IBOutlet NSWindow* window;
37 | @property (nonatomic, assign) IBOutlet EAGLView* glView;
38 |
39 | -(IBAction) toggleFullScreen:(id)sender;
40 | -(IBAction) exitFullScreen:(id)sender;
41 |
42 | @end
43 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/AppController.mm:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | #import "AppController.h"
26 | #import "AppDelegate.h"
27 |
28 | @implementation AppController
29 |
30 | static AppDelegate s_sharedApplication;
31 |
32 | @synthesize window, glView;
33 |
34 | -(void) applicationDidFinishLaunching:(NSNotification *)aNotification
35 | {
36 | // create the window
37 | // note that using NSResizableWindowMask causes the window to be a little
38 | // smaller and therefore ipad graphics are not loaded
39 | NSRect rect = NSMakeRect(200, 200, 480, 720);
40 | window = [[NSWindow alloc] initWithContentRect:rect
41 | styleMask:( NSClosableWindowMask | NSTitledWindowMask )
42 | backing:NSBackingStoreBuffered
43 | defer:YES];
44 |
45 | NSOpenGLPixelFormatAttribute attributes[] = {
46 | NSOpenGLPFADoubleBuffer,
47 | NSOpenGLPFADepthSize, 24,
48 | NSOpenGLPFAStencilSize, 8,
49 | 0
50 | };
51 |
52 | NSOpenGLPixelFormat *pixelFormat = [[[NSOpenGLPixelFormat alloc] initWithAttributes:attributes] autorelease];
53 |
54 | // allocate our GL view
55 | // (isn't there already a shared EAGLView?)
56 | glView = [[EAGLView alloc] initWithFrame:rect pixelFormat:pixelFormat];
57 |
58 | // set window parameters
59 | [window becomeFirstResponder];
60 | [window setContentView:glView];
61 | [window setTitle:@"TestCpp"];
62 | [window makeKeyAndOrderFront:self];
63 | [window setAcceptsMouseMovedEvents:NO];
64 |
65 | cocos2d::CCApplication::sharedApplication()->run();
66 | }
67 |
68 | -(BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication*)theApplication
69 | {
70 | return YES;
71 | }
72 |
73 | -(void) dealloc
74 | {
75 | cocos2d::CCDirector::sharedDirector()->end();
76 | [super dealloc];
77 | }
78 |
79 | #pragma mark -
80 | #pragma mark IB Actions
81 |
82 | -(IBAction) toggleFullScreen:(id)sender
83 | {
84 | EAGLView* pView = [EAGLView sharedEGLView];
85 | [pView setFullScreen:!pView.isFullScreen];
86 | }
87 |
88 | -(IBAction) exitFullScreen:(id)sender
89 | {
90 | [[EAGLView sharedEGLView] setFullScreen:NO];
91 | }
92 |
93 | @end
94 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/Icon.icns:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/proj.mac/Icon.icns
--------------------------------------------------------------------------------
/MacCpp/proj.mac/TestCpp.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/TestCpp.xcodeproj/project.xcworkspace/xcuserdata/leafsoar.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/MacCpp/proj.mac/TestCpp.xcodeproj/project.xcworkspace/xcuserdata/leafsoar.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/MacCpp/proj.mac/TestCpp.xcodeproj/xcuserdata/leafsoar.xcuserdatad/xcschemes/TestCpp.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
32 |
33 |
39 |
40 |
41 |
42 |
51 |
52 |
58 |
59 |
60 |
61 |
62 |
63 |
69 |
70 |
76 |
77 |
78 |
79 |
81 |
82 |
85 |
86 |
87 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/TestCpp.xcodeproj/xcuserdata/leafsoar.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | TestCpp.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 1D6058900D05DD3D006BFB54
16 |
17 | primary
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/Test_Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | ${EXECUTABLE_NAME}
9 | CFBundleIconFile
10 | Icon
11 | CFBundleIdentifier
12 | org.cocos2d-x.${PRODUCT_NAME:rfc1034identifier}
13 | CFBundleInfoDictionaryVersion
14 | 6.0
15 | CFBundleName
16 | ${PRODUCT_NAME}
17 | CFBundlePackageType
18 | APPL
19 | CFBundleShortVersionString
20 | 1.0
21 | CFBundleSignature
22 | ????
23 | CFBundleVersion
24 | 1
25 | LSMinimumSystemVersion
26 | ${MACOSX_DEPLOYMENT_TARGET}
27 | NSHumanReadableCopyright
28 | Copyright © 2012. All rights reserved.
29 | NSMainNibFile
30 | MainMenu
31 | NSPrincipalClass
32 | NSApplication
33 |
34 |
35 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/Test_Prefix.pch:
--------------------------------------------------------------------------------
1 | //
2 | // Prefix header for all source files of the 'Paralaxer' target in the 'Paralaxer' project
3 | //
4 |
5 | #ifdef __OBJC__
6 | #import
7 | #endif
8 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/en.lproj/InfoPlist.strings:
--------------------------------------------------------------------------------
1 | /* Localized versions of Info.plist keys */
2 |
3 |
--------------------------------------------------------------------------------
/MacCpp/proj.mac/main.m:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 | Copyright (c) 2010 cocos2d-x.org
3 |
4 | http://www.cocos2d-x.org
5 |
6 | Permission is hereby granted, free of charge, to any person obtaining a copy
7 | of this software and associated documentation files (the "Software"), to deal
8 | in the Software without restriction, including without limitation the rights
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | copies of the Software, and to permit persons to whom the Software is
11 | furnished to do so, subject to the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be included in
14 | all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 | THE SOFTWARE.
23 | ****************************************************************************/
24 |
25 | #import
26 |
27 | int main(int argc, char *argv[])
28 | {
29 | return NSApplicationMain(argc, (const char **)argv);
30 | }
31 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # 无间落叶 的 Cocos2d-x 代码示例
2 |
3 | 详细内容见博客
4 |
5 | 需要注意的是,当前使用的 cocos2d-x 是此时的稳定版本 2.0.4 ,所以如果你需要更新到最新的稳定版,那么需要建立新的项目,并注意代码库的API是否有改动。
6 |
7 | ## 目录说明
8 |
9 | **HelloWorld:** 提供了一个完整的 Linux 下 Eclipse 组织 Cocos2d-x 夸平台开发工程
10 |
11 | **Learn:** 作为在学习的过程中,实现的一些小功能,小例子
12 |
13 | **Libs:** 存放了第三方库资源文件
14 |
15 | **Resources:** 全局资源,是把本来应该在各个项目文件夹之下的资源,移动到上层目录,以遍学习之时,各个项目共用资源,节省资源。每个项目都说明了其使用的资源路径,在构建编译时注意
16 |
17 | **Third:** 作为调用第三方库和扩展库的使用方法
18 |
19 |
--------------------------------------------------------------------------------
/Resources/Peas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Resources/Peas.png
--------------------------------------------------------------------------------
/Resources/close.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Resources/close.png
--------------------------------------------------------------------------------
/Resources/move.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/Resources/move.jpg
--------------------------------------------------------------------------------
/ScreenSolutions/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 |
3 | #include "cocos2d.h"
4 | #include "HelloWorldScene.h"
5 |
6 | USING_NS_CC;
7 |
8 | AppDelegate::AppDelegate() {
9 |
10 | }
11 |
12 | AppDelegate::~AppDelegate() {
13 | }
14 |
15 | bool AppDelegate::applicationDidFinishLaunching() {
16 | CCDirector *pDirector = CCDirector::sharedDirector();
17 | pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
18 |
19 | pDirector->setDisplayStats(true);
20 |
21 | pDirector->setAnimationInterval(1.0 / 60);
22 |
23 | // CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
24 | // kResolutionNoBorder);
25 | // CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
26 | // kResolutionNoBorder);
27 |
28 | CCSize frameSize = CCEGLView::sharedOpenGLView()->getFrameSize();
29 | CCSize lsSize = CCSizeMake(480, 320);
30 |
31 | float scaleX = (float) frameSize.width / lsSize.width;
32 | float scaleY = (float) frameSize.height / lsSize.height;
33 |
34 | float scale = MAX(scaleX, scaleY);
35 |
36 | // if (scaleX > scaleY) {
37 | // scale = scaleX / (frameSize.height / (float) lsSize.height);
38 | // } else {
39 | // scale = scaleY / (frameSize.width / (float) lsSize.width);
40 | // }
41 |
42 | // 固定高度
43 | // if (scaleX > scaleY)
44 | // scale = scaleX / (frameSize.height / (float) lsSize.height);
45 | // else
46 | // scale = scaleX / (frameSize.width / (float) lsSize.width);
47 |
48 | // 固定宽度
49 | if (scaleX > scaleY)
50 | scale = scaleY / (frameSize.height / (float) lsSize.height);
51 | else
52 | scale = scaleY / (frameSize.width / (float) lsSize.width);
53 |
54 | CCLog("x: %f; y: %f; scale: %f", scaleX, scaleY, scale);
55 |
56 | CCEGLView::sharedOpenGLView()->setDesignResolutionSize(lsSize.width * scale,
57 | lsSize.height * scale, kResolutionNoBorder);
58 |
59 | // CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480, 320,
60 | // kResolutionNoBorder);
61 |
62 | // CCEGLView::sharedOpenGLView()->setDesignResolutionSize(480 * 1.083,
63 | // 320 * 1.083, kResolutionNoBorder);
64 |
65 | // pDirector->setContentScaleFactor(
66 | // CCEGLView::sharedOpenGLView()->getScaleY() );
67 |
68 | CCScene *pScene = HelloWorld::scene();
69 |
70 | pDirector->runWithScene(pScene);
71 |
72 | // CCSize frameSize = CCEGLView::sharedOpenGLView()->getFrameSize();
73 | CCSize winSize = CCDirector::sharedDirector()->getWinSize();
74 | CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
75 | CCPoint visibleOrigin = CCDirector::sharedDirector()->getVisibleOrigin();
76 |
77 | CCLog("FrameSize: width[%f], height[%f]", frameSize.width,
78 | frameSize.height);
79 | CCLog("WinSize: width[%f], height[%f]", winSize.width, winSize.height);
80 | CCLog("VisibleSize: width[%f], height[%f]", visibleSize.width,
81 | visibleSize.height);
82 | CCLog("VisibleOrigin: x[%f], y[%f]", visibleOrigin.x, visibleOrigin.y);
83 |
84 | CCLog("XScale: %f, YScale: %f", CCEGLView::sharedOpenGLView()->getScaleX(),
85 | CCEGLView::sharedOpenGLView()->getScaleY());
86 |
87 | return true;
88 | }
89 |
90 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
91 | void AppDelegate::applicationDidEnterBackground() {
92 | CCDirector::sharedDirector()->pause();
93 |
94 | // if you use SimpleAudioEngine, it must be pause
95 | // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
96 | }
97 |
98 | // this function will be called when the app is active again
99 | void AppDelegate::applicationWillEnterForeground() {
100 | CCDirector::sharedDirector()->resume();
101 |
102 | // if you use SimpleAudioEngine, it must resume here
103 | // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
104 | }
105 |
--------------------------------------------------------------------------------
/ScreenSolutions/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "CCApplication.h"
5 |
6 | /**
7 | @brief The cocos2d Application.
8 |
9 | The reason for implement as private inheritance is to hide some interface call by CCDirector.
10 | */
11 | class AppDelegate : private cocos2d::CCApplication
12 | {
13 | public:
14 | AppDelegate();
15 | virtual ~AppDelegate();
16 |
17 | /**
18 | @brief Implement CCDirector and CCScene init code here.
19 | @return true Initialize success, app continue.
20 | @return false Initialize failed, app terminate.
21 | */
22 | virtual bool applicationDidFinishLaunching();
23 |
24 | /**
25 | @brief The function be called when the application enter background
26 | @param the pointer of the application
27 | */
28 | virtual void applicationDidEnterBackground();
29 |
30 | /**
31 | @brief The function be called when the application enter foreground
32 | @param the pointer of the application
33 | */
34 | virtual void applicationWillEnterForeground();
35 | };
36 |
37 | #endif // _APP_DELEGATE_H_
38 |
39 |
--------------------------------------------------------------------------------
/ScreenSolutions/Classes/HelloWorldScene.cpp:
--------------------------------------------------------------------------------
1 | #include "HelloWorldScene.h"
2 | #include "SimpleAudioEngine.h"
3 |
4 | using namespace cocos2d;
5 | using namespace CocosDenshion;
6 |
7 | CCScene* HelloWorld::scene() {
8 | // 'scene' is an autorelease object
9 | CCScene *scene = CCScene::create();
10 |
11 | CCLayer* b = CCLayer::create();
12 | scene->addChild(b);
13 |
14 | CCSize size = CCDirector::sharedDirector()->getWinSize();
15 | CCPoint center = ccp(size.width/2, size.height/2);
16 | CCSprite* pb = CCSprite::create("Back.jpg");
17 | pb->setPosition(center);
18 | b->addChild(pb, 0);
19 |
20 | HelloWorld *lsLayer = HelloWorld::create();
21 |
22 | scene->addChild(lsLayer);
23 |
24 | return scene;
25 | }
26 |
27 | // on "init" you need to initialize your instance
28 | bool HelloWorld::init() {
29 | if (!CCLayer::init()) {
30 | return false;
31 | }
32 |
33 | CCMenuItemImage *pCloseItem = CCMenuItemImage::create("CloseNormal.png",
34 | "CloseSelected.png", this,
35 | menu_selector(HelloWorld::menuCloseCallback));
36 | pCloseItem->setPosition(
37 | ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20));
38 |
39 | // create menu, it's an autorelease object
40 | CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
41 | pMenu->setPosition(CCPointZero);
42 | this->addChild(pMenu, 1);
43 |
44 | CCSize size = CCDirector::sharedDirector()->getWinSize();
45 |
46 | CCPoint center = ccp(size.width/2, size.height/2);
47 |
48 | // 大小 600x500
49 | // CCSprite* pb = CCSprite::create("Back.jpg");
50 | // pb->setPosition(center);
51 | // this->addChild(pb, 0);
52 |
53 | // 480x320
54 | CCSprite* pSprite = CCSprite::create("HelloWorld.png");
55 | pSprite->setPosition(center);
56 | this->addChild(pSprite, 0);
57 |
58 | // 37x37
59 | CCSprite* p1 = CCSprite::create("Peas.png");
60 | p1->setPosition(ccpAdd(center, ccp(-240, -160)));
61 | this->addChild(p1);
62 |
63 | CCSprite* p2 = CCSprite::create("Peas.png");
64 | p2->setPosition(ccpAdd(center, ccp(240, 160)));
65 | this->addChild(p2);
66 |
67 | CCSprite* p3 = CCSprite::create("Peas.png");
68 | p3->setPosition(ccpAdd(center, ccp(-240, 160)));
69 | this->addChild(p3);
70 |
71 | CCSprite* p4 = CCSprite::create("Peas.png");
72 | p4->setPosition(ccpAdd(center, ccp(240, -160)));
73 | this->addChild(p4);
74 |
75 | // CCSprite* p5 = CCSprite::create("Peas.png");
76 | // p5->setPosition(ccp(0, 40));
77 | // this->addChild(p5);
78 |
79 | return true;
80 | }
81 |
82 | //void HelloWorld::visit() {
83 | // glEnable(GL_SCISSOR_TEST); // 开启显示指定区域
84 | // glScissor(40, 0, 960, 640); // 只显示当前窗口的区域
85 | // glScissor(10, 0, 240, 160); // 只显示当前窗口的区域
86 | // CCLayer::visit(); // 调用下面的方法
87 | // glDisable(GL_SCISSOR_TEST); // 禁用
88 | //}
89 |
90 | void HelloWorld::menuCloseCallback(CCObject* pSender) {
91 | CCDirector::sharedDirector()->end();
92 |
93 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
94 | exit(0);
95 | #endif
96 | }
97 |
--------------------------------------------------------------------------------
/ScreenSolutions/Classes/HelloWorldScene.h:
--------------------------------------------------------------------------------
1 | #ifndef __HELLOWORLD_SCENE_H__
2 | #define __HELLOWORLD_SCENE_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | class HelloWorld : public cocos2d::CCLayer
7 | {
8 | public:
9 | virtual bool init();
10 |
11 | static cocos2d::CCScene* scene();
12 |
13 | void menuCloseCallback(CCObject* pSender);
14 |
15 | CREATE_FUNC(HelloWorld);
16 |
17 | // virtual void visit();
18 |
19 | private:
20 | CCLayer* m_pBackground;
21 | };
22 |
23 | #endif // __HELLOWORLD_SCENE_H__
24 |
--------------------------------------------------------------------------------
/ScreenSolutions/README.md:
--------------------------------------------------------------------------------
1 | # ScreenSolutions 屏幕适配 项目代码
2 |
3 | 源代码路径: ./Classes
4 |
5 | 资源文件路径: ./Resources
6 |
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/Back.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/Back.jpg
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/CloseNormal.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/CloseNormal.png
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/CloseSelected.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/CloseSelected.png
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/HelloWorld.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/HelloWorld.png
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/Peas.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/Peas.png
--------------------------------------------------------------------------------
/ScreenSolutions/Resources/fonts/prim36.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/leafsoar/ls-cocos2d-x/66084596adc083cc1f103ae67174614b5211b2d4/ScreenSolutions/Resources/fonts/prim36.png
--------------------------------------------------------------------------------
/ScreenSolutions/proj.linux/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /obj
3 |
--------------------------------------------------------------------------------
/ScreenSolutions/proj.linux/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | ScreenSolutions_dx
4 |
5 |
6 | libCocosDenshion
7 | libcocos2d
8 |
9 |
10 |
11 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
12 | clean,full,incremental,
13 |
14 |
15 | ?name?
16 |
17 |
18 |
19 | org.eclipse.cdt.make.core.append_environment
20 | true
21 |
22 |
23 | org.eclipse.cdt.make.core.autoBuildTarget
24 | all
25 |
26 |
27 | org.eclipse.cdt.make.core.buildArguments
28 |
29 |
30 |
31 | org.eclipse.cdt.make.core.buildCommand
32 | make
33 |
34 |
35 | org.eclipse.cdt.make.core.buildLocation
36 | ${workspace_loc:/HelloCocos2dx/Debug}
37 |
38 |
39 | org.eclipse.cdt.make.core.cleanBuildTarget
40 | clean
41 |
42 |
43 | org.eclipse.cdt.make.core.contents
44 | org.eclipse.cdt.make.core.activeConfigSettings
45 |
46 |
47 | org.eclipse.cdt.make.core.enableAutoBuild
48 | false
49 |
50 |
51 | org.eclipse.cdt.make.core.enableCleanBuild
52 | true
53 |
54 |
55 | org.eclipse.cdt.make.core.enableFullBuild
56 | true
57 |
58 |
59 | org.eclipse.cdt.make.core.fullBuildTarget
60 | all
61 |
62 |
63 | org.eclipse.cdt.make.core.stopOnError
64 | true
65 |
66 |
67 | org.eclipse.cdt.make.core.useDefaultBuildCmd
68 | true
69 |
70 |
71 |
72 |
73 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
74 | full,incremental,
75 |
76 |
77 |
78 |
79 |
80 | org.eclipse.cdt.core.cnature
81 | org.eclipse.cdt.core.ccnature
82 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
83 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
84 |
85 |
86 |
87 | Classes
88 | 2
89 | PARENT-1-PROJECT_LOC/Classes
90 |
91 |
92 | Resources
93 | 2
94 | PARENT-1-PROJECT_LOC/Resources
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/ScreenSolutions/proj.linux/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | TARGET = leafsoar
4 | CCFLAGS = -Wall
5 | CXXFLAGS = -Wall
6 | VISIBILITY =
7 |
8 | # COCOS2DX_ROOT = /home/leafsoar/...
9 |
10 | COCOS2DX_PATH = $(COCOS2DX_ROOT)/cocos2dx
11 | INCLUDES = -I../ \
12 | -I../Classes \
13 | -I$(COCOS2DX_PATH) \
14 | -I$(COCOS2DX_PATH)/platform/third_party/linux \
15 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libfreetype2 \
16 | -I$(COCOS2DX_PATH)/cocoa \
17 | -I$(COCOS2DX_PATH)/include \
18 | -I$(COCOS2DX_PATH)/platform \
19 | -I$(COCOS2DX_PATH)/platform/linux \
20 | -I$(COCOS2DX_PATH)/platform/third_party/linux/glew-1.7.0/glew-1.7.0/include/ \
21 | -I$(COCOS2DX_PATH)/kazmath/include \
22 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
23 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg \
24 | -I$(COCOS2DX_ROOT)/CocosDenshion/include \
25 | # -I$(COCOS2DX_ROOT)/extensions/ \
26 |
27 | DEFINES = -DLINUX
28 |
29 | define all-cpp-files
30 | $(patsubst ./%,%, $(shell find ../Classes ./ -name "*.cpp"))
31 | endef
32 |
33 | define all-cpp-dir
34 | $(patsubst ../%,obj/%, $(shell find ../Classes -type d))
35 | endef
36 |
37 | OBJDIR=obj/Classes
38 |
39 | OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(call all-cpp-files))
40 | OBJECTS_DIR=$(call all-cpp-dir)
41 |
42 | # 如果目录不存在,则创建相应的目录
43 | $(shell mkdir -p obj)
44 | $(shell mkdir -p $(OBJECTS_DIR))
45 |
46 | #echo:
47 | # @echo $(OBJECTS_DIR)
48 |
49 | #OBJECTS = ./main.o \
50 | # ../Classes/AppDelegate.o
51 |
52 | LBITS := $(shell getconf LONG_BIT)
53 | ifeq ($(LBITS),64)
54 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries/lib64
55 | else
56 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries
57 | endif
58 | STATICLIBS =
59 | STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
60 | $(STATICLIBS_DIR)/libxml2.a \
61 | $(STATICLIBS_DIR)/libpng.a \
62 | $(STATICLIBS_DIR)/libjpeg.a \
63 | $(STATICLIBS_DIR)/libtiff.a \
64 | # $(STATICLIBS_DIR)/libGLEW.a \
65 |
66 | SHAREDLIBS =
67 | ifeq ($(LBITS),64)
68 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/lib64/api/lib
69 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex64
70 | else
71 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/api/lib
72 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex
73 | endif
74 |
75 | SHAREDLIBS += -lglfw -lGL
76 | SHAREDLIBS += -Wl,-rpath,$(SHAREDLIBS_DIR)
77 | SHAREDLIBS += -L$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib -lGLEW
78 | SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib
79 |
80 |
81 | BIN_DIR_ROOT=bin
82 | BIN_DIR = $(BIN_DIR_ROOT)
83 |
84 | debug: BIN_DIR = $(BIN_DIR_ROOT)/debug
85 | debug: CCFLAGS += -g3 -O0
86 | debug: CXXFLAGS += -g3 -O0
87 | debug: SHAREDLIBS += -L$(COCOS2DX_ROOT)/lib/linux/Debug -lcocos2d -lrt -lz -lcocosdenshion
88 | debug: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Debug/
89 | debug: DEFINES += -DDEBUG
90 | debug: $(TARGET)
91 |
92 | release: BIN_DIR = $(BIN_DIR_ROOT)/release
93 | release: CCFLAGS += -O3
94 | release: CXXFLAGS += -O3
95 | release: SHAREDLIBS += -L.$(COCOS2DX_ROOT)/lib/linux/Release -lcocos2d -lrt -lz -lcocosdenshion
96 | release: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Release/
97 | release: DEFINES += -DNDEBUG
98 | release: $(TARGET)
99 |
100 | ####### Build rules
101 | $(TARGET): $(OBJECTS)
102 | mkdir -p $(BIN_DIR)
103 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(OBJECTS) -o $(BIN_DIR)/$(TARGET) $(SHAREDLIBS) $(STATICLIBS)
104 |
105 | ####### Compile
106 | $(OBJDIR)/%.o: %.cpp
107 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
108 |
109 | %.o: %.c
110 | $(CC) $(CCFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
111 |
112 | clean:
113 | rm -f $(OBJECTS) $(TARGET) core
114 |
--------------------------------------------------------------------------------
/ScreenSolutions/proj.linux/main.cpp:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "../Classes/AppDelegate.h"
3 | #include "cocos2d.h"
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | USING_NS_CC;
11 |
12 | // 500 is enough?
13 | #define MAXPATHLEN 500
14 |
15 | int main(int argc, char **argv) {
16 | // get application path
17 | int length;
18 | char fullpath[MAXPATHLEN];
19 | length = readlink("/proc/self/exe", fullpath, sizeof(fullpath));
20 | fullpath[length] = '\0';
21 |
22 | std::string resourcePath = fullpath;
23 | resourcePath = resourcePath.substr(0, resourcePath.find_last_of("/"));
24 | resourcePath += "/../../../Resources/";
25 |
26 | // create the application instance
27 | AppDelegate app;
28 | CCApplication::sharedApplication()->setResourceRootPath(
29 | resourcePath.c_str());
30 | CCEGLView* eglView = CCEGLView::sharedOpenGLView();
31 | // eglView->setFrameSize(720, 540);
32 | // eglView->setFrameSize(600, 320);
33 | // eglView->setFrameSize(560, 360);
34 | eglView->setFrameSize(480, 300);
35 | //
36 | // eglView->setFrameSize(600, 480);
37 | // eglView->setFrameSize(1040, 640);
38 | // eglView->setFrameSize(260, 160);
39 |
40 | return CCApplication::sharedApplication()->run();
41 | }
42 |
--------------------------------------------------------------------------------
/ScreenSolutions/proj.linux/main.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_H__
2 | #define __MAIN_H__
3 |
4 | // C RunTime Header Files
5 | #include "CCStdC.h"
6 |
7 | #endif // __MAIN_H__
8 |
--------------------------------------------------------------------------------
/Third/Classes/AppDelegate.cpp:
--------------------------------------------------------------------------------
1 | #include "AppDelegate.h"
2 |
3 | #include "cocos2d.h"
4 | #include "HelloWorldScene.h"
5 |
6 | USING_NS_CC;
7 |
8 | AppDelegate::AppDelegate()
9 | {
10 |
11 | }
12 |
13 | AppDelegate::~AppDelegate()
14 | {
15 | }
16 |
17 | bool AppDelegate::applicationDidFinishLaunching()
18 | {
19 | // initialize director
20 | CCDirector *pDirector = CCDirector::sharedDirector();
21 | pDirector->setOpenGLView(CCEGLView::sharedOpenGLView());
22 |
23 | // turn on display FPS
24 | pDirector->setDisplayStats(true);
25 |
26 | // set FPS. the default value is 1.0/60 if you don't call this
27 | pDirector->setAnimationInterval(1.0 / 60);
28 |
29 | // create a scene. it's an autorelease object
30 | // CCScene *pScene = HelloWorld::scene();
31 |
32 | // run
33 | // pDirector->runWithScene(pScene);
34 |
35 | return true;
36 | }
37 |
38 | // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
39 | void AppDelegate::applicationDidEnterBackground()
40 | {
41 | CCDirector::sharedDirector()->pause();
42 |
43 | // if you use SimpleAudioEngine, it must be pause
44 | // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
45 | }
46 |
47 | // this function will be called when the app is active again
48 | void AppDelegate::applicationWillEnterForeground()
49 | {
50 | CCDirector::sharedDirector()->resume();
51 |
52 | // if you use SimpleAudioEngine, it must resume here
53 | // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
54 | }
55 |
--------------------------------------------------------------------------------
/Third/Classes/AppDelegate.h:
--------------------------------------------------------------------------------
1 | #ifndef _APP_DELEGATE_H_
2 | #define _APP_DELEGATE_H_
3 |
4 | #include "CCApplication.h"
5 |
6 | /**
7 | @brief The cocos2d Application.
8 |
9 | The reason for implement as private inheritance is to hide some interface call by CCDirector.
10 | */
11 | class AppDelegate : private cocos2d::CCApplication
12 | {
13 | public:
14 | AppDelegate();
15 | virtual ~AppDelegate();
16 |
17 | /**
18 | @brief Implement CCDirector and CCScene init code here.
19 | @return true Initialize success, app continue.
20 | @return false Initialize failed, app terminate.
21 | */
22 | virtual bool applicationDidFinishLaunching();
23 |
24 | /**
25 | @brief The function be called when the application enter background
26 | @param the pointer of the application
27 | */
28 | virtual void applicationDidEnterBackground();
29 |
30 | /**
31 | @brief The function be called when the application enter foreground
32 | @param the pointer of the application
33 | */
34 | virtual void applicationWillEnterForeground();
35 | };
36 |
37 | #endif // _APP_DELEGATE_H_
38 |
39 |
--------------------------------------------------------------------------------
/Third/Classes/HelloWorldScene.cpp:
--------------------------------------------------------------------------------
1 | #include "HelloWorldScene.h"
2 |
3 | using namespace cocos2d;
4 |
5 | CCScene* HelloWorld::scene()
6 | {
7 | // 'scene' is an autorelease object
8 | CCScene *scene = CCScene::create();
9 |
10 | // 'layer' is an autorelease object
11 | HelloWorld *layer = HelloWorld::create();
12 |
13 | // add layer as a child to scene
14 | scene->addChild(layer);
15 |
16 | // return the scene
17 | return scene;
18 | }
19 |
20 | // on "init" you need to initialize your instance
21 | bool HelloWorld::init()
22 | {
23 | //////////////////////////////
24 | // 1. super init first
25 | if ( !CCLayer::init() )
26 | {
27 | return false;
28 | }
29 |
30 | /////////////////////////////
31 | // 2. add a menu item with "X" image, which is clicked to quit the program
32 | // you may modify it.
33 |
34 | // add a "close" icon to exit the progress. it's an autorelease object
35 | CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
36 | "CloseNormal.png",
37 | "CloseSelected.png",
38 | this,
39 | menu_selector(HelloWorld::menuCloseCallback) );
40 | pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
41 |
42 | // create menu, it's an autorelease object
43 | CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
44 | pMenu->setPosition( CCPointZero );
45 | this->addChild(pMenu, 1);
46 |
47 | /////////////////////////////
48 | // 3. add your codes below...
49 |
50 | // add a label shows "Hello World"
51 | // create and initialize a label
52 | CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Thonburi", 34);
53 |
54 | // ask director the window size
55 | CCSize size = CCDirector::sharedDirector()->getWinSize();
56 |
57 | // position the label on the center of the screen
58 | pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
59 |
60 | // add the label as a child to this layer
61 | this->addChild(pLabel, 1);
62 |
63 | // add "HelloWorld" splash screen"
64 | CCSprite* pSprite = CCSprite::create("HelloWorld.png");
65 |
66 | // position the sprite on the center of the screen
67 | pSprite->setPosition( ccp(size.width/2, size.height/2) );
68 |
69 | // add the sprite as a child to this layer
70 | this->addChild(pSprite, 0);
71 |
72 | return true;
73 | }
74 |
75 | void HelloWorld::menuCloseCallback(CCObject* pSender)
76 | {
77 | CCDirector::sharedDirector()->end();
78 |
79 | #if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
80 | exit(0);
81 | #endif
82 | }
83 |
--------------------------------------------------------------------------------
/Third/Classes/HelloWorldScene.h:
--------------------------------------------------------------------------------
1 | #ifndef __HELLOWORLD_SCENE_H__
2 | #define __HELLOWORLD_SCENE_H__
3 |
4 | #include "cocos2d.h"
5 |
6 | class HelloWorld : public cocos2d::CCLayer
7 | {
8 | public:
9 | // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
10 | virtual bool init();
11 |
12 | // there's no 'id' in cpp, so we recommand to return the exactly class pointer
13 | static cocos2d::CCScene* scene();
14 |
15 | // a selector callback
16 | void menuCloseCallback(CCObject* pSender);
17 |
18 | // implement the "static node()" method manually
19 | CREATE_FUNC(HelloWorld);
20 | };
21 |
22 | #endif // __HELLOWORLD_SCENE_H__
23 |
--------------------------------------------------------------------------------
/Third/README.md:
--------------------------------------------------------------------------------
1 | # Third 项目代码 (扩展库,第三方库的使用方法)
2 |
3 | 源代码路径: ./Classes
4 |
5 | 资源文件路径: ./../Resources
6 |
--------------------------------------------------------------------------------
/Third/proj.linux/.gitignore:
--------------------------------------------------------------------------------
1 | /bin
2 | /obj
3 |
--------------------------------------------------------------------------------
/Third/proj.linux/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | Third
4 |
5 |
6 | libCocosDenshion
7 |
8 |
9 |
10 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
11 | clean,full,incremental,
12 |
13 |
14 | ?name?
15 |
16 |
17 |
18 | org.eclipse.cdt.make.core.append_environment
19 | true
20 |
21 |
22 | org.eclipse.cdt.make.core.autoBuildTarget
23 | all
24 |
25 |
26 | org.eclipse.cdt.make.core.buildArguments
27 |
28 |
29 |
30 | org.eclipse.cdt.make.core.buildCommand
31 | make
32 |
33 |
34 | org.eclipse.cdt.make.core.buildLocation
35 | ${workspace_loc:/HelloCocos2dx/Debug}
36 |
37 |
38 | org.eclipse.cdt.make.core.cleanBuildTarget
39 | clean
40 |
41 |
42 | org.eclipse.cdt.make.core.contents
43 | org.eclipse.cdt.make.core.activeConfigSettings
44 |
45 |
46 | org.eclipse.cdt.make.core.enableAutoBuild
47 | false
48 |
49 |
50 | org.eclipse.cdt.make.core.enableCleanBuild
51 | true
52 |
53 |
54 | org.eclipse.cdt.make.core.enableFullBuild
55 | true
56 |
57 |
58 | org.eclipse.cdt.make.core.fullBuildTarget
59 | all
60 |
61 |
62 | org.eclipse.cdt.make.core.stopOnError
63 | true
64 |
65 |
66 | org.eclipse.cdt.make.core.useDefaultBuildCmd
67 | true
68 |
69 |
70 |
71 |
72 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
73 | full,incremental,
74 |
75 |
76 |
77 |
78 |
79 | org.eclipse.cdt.core.cnature
80 | org.eclipse.cdt.core.ccnature
81 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
82 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
83 |
84 |
85 |
86 | Classes
87 | 2
88 | PARENT-1-PROJECT_LOC/Classes
89 |
90 |
91 | Resources
92 | 2
93 | PARENT-1-PROJECT_LOC/Resources
94 |
95 |
96 |
97 |
98 | copy_PARENT
99 | $%7BPARENT-1-PROJECT_LOC%7D/ls-cocos2d-x/Learn
100 |
101 |
102 |
103 |
--------------------------------------------------------------------------------
/Third/proj.linux/Makefile:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | TARGET = leafsoar
4 | CCFLAGS = -Wall
5 | CXXFLAGS = -Wall
6 | VISIBILITY =
7 |
8 | # COCOS2DX_ROOT = /home/leafsoar/...
9 |
10 | COCOS2DX_PATH = $(COCOS2DX_ROOT)/cocos2dx
11 | INCLUDES = -I../ \
12 | -I../Classes \
13 | -I$(COCOS2DX_PATH) \
14 | -I$(COCOS2DX_PATH)/platform/third_party/linux \
15 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libfreetype2 \
16 | -I$(COCOS2DX_PATH)/cocoa \
17 | -I$(COCOS2DX_PATH)/include \
18 | -I$(COCOS2DX_PATH)/platform \
19 | -I$(COCOS2DX_PATH)/platform/linux \
20 | -I$(COCOS2DX_PATH)/platform/third_party/linux/glew-1.7.0/glew-1.7.0/include/ \
21 | -I$(COCOS2DX_PATH)/kazmath/include \
22 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libxml2 \
23 | -I$(COCOS2DX_PATH)/platform/third_party/linux/libjpeg \
24 | -I$(COCOS2DX_ROOT)/CocosDenshion/include \
25 | # -I$(COCOS2DX_ROOT)/extensions/ \
26 |
27 | DEFINES = -DLINUX
28 |
29 | define all-cpp-files
30 | $(patsubst ./%,%, $(shell find ../Classes ./ -name "*.cpp"))
31 | endef
32 |
33 | define all-cpp-dir
34 | $(patsubst ../%,obj/%, $(shell find ../Classes -type d))
35 | endef
36 |
37 | OBJDIR=obj/Classes
38 |
39 | OBJECTS=$(patsubst %.cpp,$(OBJDIR)/%.o,$(call all-cpp-files))
40 | OBJECTS_DIR=$(call all-cpp-dir)
41 |
42 | # 如果目录不存在,则创建相应的目录
43 | $(shell mkdir -p obj)
44 | $(shell mkdir -p $(OBJECTS_DIR))
45 |
46 | #echo:
47 | # @echo $(OBJECTS_DIR)
48 |
49 | #OBJECTS = ./main.o \
50 | # ../Classes/AppDelegate.o
51 |
52 | LBITS := $(shell getconf LONG_BIT)
53 | ifeq ($(LBITS),64)
54 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries/lib64
55 | else
56 | STATICLIBS_DIR = $(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/libraries
57 | endif
58 | STATICLIBS =
59 | STATICLIBS = $(STATICLIBS_DIR)/libfreetype.a \
60 | $(STATICLIBS_DIR)/libxml2.a \
61 | $(STATICLIBS_DIR)/libpng.a \
62 | $(STATICLIBS_DIR)/libjpeg.a \
63 | $(STATICLIBS_DIR)/libtiff.a \
64 | # $(STATICLIBS_DIR)/libGLEW.a \
65 |
66 | SHAREDLIBS =
67 | ifeq ($(LBITS),64)
68 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/lib64/api/lib
69 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex64
70 | else
71 | SHAREDLIBS_DIR = $(COCOS2DX_ROOT)/CocosDenshion/third_party/fmod/api/lib
72 | SHAREDLIBS = -L$(SHAREDLIBS_DIR) -lfmodex
73 | endif
74 |
75 | SHAREDLIBS += -lglfw -lGL
76 | SHAREDLIBS += -Wl,-rpath,$(SHAREDLIBS_DIR)
77 | SHAREDLIBS += -L$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib -lGLEW
78 | SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/cocos2dx/platform/third_party/linux/glew-1.7.0/glew-1.7.0/lib
79 |
80 |
81 | BIN_DIR_ROOT=bin
82 | BIN_DIR = $(BIN_DIR_ROOT)
83 |
84 | debug: BIN_DIR = $(BIN_DIR_ROOT)/debug
85 | debug: CCFLAGS += -g3 -O0
86 | debug: CXXFLAGS += -g3 -O0
87 | debug: SHAREDLIBS += -L$(COCOS2DX_ROOT)/lib/linux/Debug -lcocos2d -lrt -lz -lcocosdenshion
88 | debug: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Debug/
89 | debug: DEFINES += -DDEBUG
90 | debug: $(TARGET)
91 |
92 | release: BIN_DIR = $(BIN_DIR_ROOT)/release
93 | release: CCFLAGS += -O3
94 | release: CXXFLAGS += -O3
95 | release: SHAREDLIBS += -L.$(COCOS2DX_ROOT)/lib/linux/Release -lcocos2d -lrt -lz -lcocosdenshion
96 | release: SHAREDLIBS += -Wl,-rpath,$(COCOS2DX_ROOT)/lib/linux/Release/
97 | release: DEFINES += -DNDEBUG
98 | release: $(TARGET)
99 |
100 | ####### Build rules
101 | $(TARGET): $(OBJECTS)
102 | mkdir -p $(BIN_DIR)
103 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(OBJECTS) -o $(BIN_DIR)/$(TARGET) $(SHAREDLIBS) $(STATICLIBS)
104 |
105 | ####### Compile
106 | $(OBJDIR)/%.o: %.cpp
107 | $(CXX) $(CXXFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
108 |
109 | %.o: %.c
110 | $(CC) $(CCFLAGS) $(INCLUDES) $(DEFINES) $(VISIBILITY) -c $< -o $@
111 |
112 | clean:
113 | rm -f $(OBJECTS) $(TARGET) core
114 |
--------------------------------------------------------------------------------
/Third/proj.linux/main.cpp:
--------------------------------------------------------------------------------
1 | #include "main.h"
2 | #include "../Classes/AppDelegate.h"
3 | #include "cocos2d.h"
4 |
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | USING_NS_CC;
12 |
13 | // 500 is enough?
14 | #define MAXPATHLEN 500
15 |
16 | int main(int argc, char **argv)
17 | {
18 | // get application path
19 | int length;
20 | char fullpath[MAXPATHLEN];
21 | length = readlink("/proc/self/exe", fullpath, sizeof(fullpath));
22 | fullpath[length] = '\0';
23 |
24 | std::string resourcePath = fullpath;
25 | resourcePath = resourcePath.substr(0, resourcePath.find_last_of("/"));
26 | resourcePath += "/../../../Resources/";
27 |
28 | // create the application instance
29 | AppDelegate app;
30 | CCApplication::sharedApplication()->setResourceRootPath(resourcePath.c_str());
31 | CCEGLView* eglView = CCEGLView::sharedOpenGLView();
32 | eglView->setFrameSize(720, 480);
33 |
34 | return CCApplication::sharedApplication()->run();
35 | }
36 |
--------------------------------------------------------------------------------
/Third/proj.linux/main.h:
--------------------------------------------------------------------------------
1 | #ifndef __MAIN_H__
2 | #define __MAIN_H__
3 |
4 | // C RunTime Header Files
5 | #include "CCStdC.h"
6 |
7 | #endif // __MAIN_H__
8 |
--------------------------------------------------------------------------------