issue #4895:Add test case
|
@ -7,7 +7,7 @@ import os, os.path
|
|||
import shutil
|
||||
from optparse import OptionParser
|
||||
|
||||
CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests']
|
||||
CPP_SAMPLES = ['cpp-empty-test', 'cpp-tests', 'game-controller-test']
|
||||
LUA_SAMPLES = ['lua-empty-test', 'lua-tests']
|
||||
ALL_SAMPLES = CPP_SAMPLES + LUA_SAMPLES
|
||||
|
||||
|
@ -216,6 +216,7 @@ def build_samples(target,ndk_build_param,android_platform,build_mode):
|
|||
|
||||
target_proj_path_map = {
|
||||
"cpp-empty-test": "tests/cpp-empty-test/proj.android",
|
||||
"game-controller-test": "tests/game-controller-test/proj.android",
|
||||
"cpp-tests": "tests/cpp-tests/proj.android",
|
||||
"lua-empty-test": "tests/lua-empty-test/project/proj.android",
|
||||
"lua-tests": "tests/lua-tests/project/proj.android"
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
#include "AppDelegate.h"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include "GameControllerTest.h"
|
||||
#include "AppMacros.h"
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace std;
|
||||
|
||||
AppDelegate::AppDelegate() {
|
||||
|
||||
}
|
||||
|
||||
AppDelegate::~AppDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
bool AppDelegate::applicationDidFinishLaunching() {
|
||||
// initialize director
|
||||
auto director = Director::getInstance();
|
||||
auto glview = director->getOpenGLView();
|
||||
if(!glview) {
|
||||
glview = GLView::create("Cpp Empty Test");
|
||||
director->setOpenGLView(glview);
|
||||
}
|
||||
|
||||
director->setOpenGLView(glview);
|
||||
|
||||
// Set the design resolution
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
|
||||
// a bug in DirectX 11 level9-x on the device prevents ResolutionPolicy::NO_BORDER from working correctly
|
||||
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::SHOW_ALL);
|
||||
#else
|
||||
glview->setDesignResolutionSize(designResolutionSize.width, designResolutionSize.height, ResolutionPolicy::NO_BORDER);
|
||||
#endif
|
||||
|
||||
Size frameSize = glview->getFrameSize();
|
||||
|
||||
vector<string> searchPath;
|
||||
|
||||
// In this demo, we select resource according to the frame's height.
|
||||
// If the resource size is different from design resolution size, you need to set contentScaleFactor.
|
||||
// We use the ratio of resource's height to the height of design resolution,
|
||||
// this can make sure that the resource's height could fit for the height of design resolution.
|
||||
|
||||
// if the frame's height is larger than the height of medium resource size, select large resource.
|
||||
if (frameSize.height > mediumResource.size.height)
|
||||
{
|
||||
searchPath.push_back(largeResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(largeResource.size.height/designResolutionSize.height, largeResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
// if the frame's height is larger than the height of small resource size, select medium resource.
|
||||
else if (frameSize.height > smallResource.size.height)
|
||||
{
|
||||
searchPath.push_back(mediumResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(mediumResource.size.height/designResolutionSize.height, mediumResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
// if the frame's height is smaller than the height of medium resource size, select small resource.
|
||||
else
|
||||
{
|
||||
searchPath.push_back(smallResource.directory);
|
||||
|
||||
director->setContentScaleFactor(MIN(smallResource.size.height/designResolutionSize.height, smallResource.size.width/designResolutionSize.width));
|
||||
}
|
||||
|
||||
// set searching path
|
||||
FileUtils::getInstance()->setSearchPaths(searchPath);
|
||||
|
||||
// turn on display FPS
|
||||
director->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
director->setAnimationInterval(1.0 / 60);
|
||||
|
||||
// create a scene. it's an autorelease object
|
||||
auto scene = GameControllerTest::scene();
|
||||
|
||||
// run
|
||||
director->runWithScene(scene);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too
|
||||
void AppDelegate::applicationDidEnterBackground() {
|
||||
Director::getInstance()->stopAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must be pause
|
||||
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
|
||||
}
|
||||
|
||||
// this function will be called when the app is active again
|
||||
void AppDelegate::applicationWillEnterForeground() {
|
||||
Director::getInstance()->startAnimation();
|
||||
|
||||
// if you use SimpleAudioEngine, it must resume here
|
||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef _APP_DELEGATE_H_
|
||||
#define _APP_DELEGATE_H_
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
/**
|
||||
@brief The cocos2d Application.
|
||||
|
||||
The reason for implement as private inheritance is to hide some interface call by Director.
|
||||
*/
|
||||
class AppDelegate : private cocos2d::Application
|
||||
{
|
||||
public:
|
||||
AppDelegate();
|
||||
virtual ~AppDelegate();
|
||||
|
||||
/**
|
||||
@brief Implement Director and Scene init code here.
|
||||
@return true Initialize success, app continue.
|
||||
@return false Initialize failed, app terminate.
|
||||
*/
|
||||
virtual bool applicationDidFinishLaunching();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter background
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationDidEnterBackground();
|
||||
|
||||
/**
|
||||
@brief The function be called when the application enter foreground
|
||||
@param the pointer of the application
|
||||
*/
|
||||
virtual void applicationWillEnterForeground();
|
||||
};
|
||||
|
||||
#endif // _APP_DELEGATE_H_
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#ifndef __APPMACROS_H__
|
||||
#define __APPMACROS_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
/* For demonstrating using one design resolution to match different resources,
|
||||
or one resource to match different design resolutions.
|
||||
|
||||
[Situation 1] Using one design resolution to match different resources.
|
||||
Please look into Appdelegate::applicationDidFinishLaunching.
|
||||
We check current device frame size to decide which resource need to be selected.
|
||||
So if you want to test this situation which said in title '[Situation 1]',
|
||||
you should change ios simulator to different device(e.g. iphone, iphone-retina3.5, iphone-retina4.0, ipad, ipad-retina),
|
||||
or change the window size in "proj.XXX/main.cpp" by "CCEGLView::setFrameSize" if you are using win32 or linux plaform
|
||||
and modify "proj.mac/AppController.mm" by changing the window rectangle.
|
||||
|
||||
[Situation 2] Using one resource to match different design resolutions.
|
||||
The coordinates in your codes is based on your current design resolution rather than resource size.
|
||||
Therefore, your design resolution could be very large and your resource size could be small.
|
||||
To test this, just define the marco 'TARGET_DESIGN_RESOLUTION_SIZE' to 'DESIGN_RESOLUTION_2048X1536'
|
||||
and open iphone simulator or create a window of 480x320 size.
|
||||
|
||||
[Note] Normally, developer just need to define one design resolution(e.g. 960x640) with one or more resources.
|
||||
*/
|
||||
|
||||
#define DESIGN_RESOLUTION_480X320 0
|
||||
#define DESIGN_RESOLUTION_1024X768 1
|
||||
#define DESIGN_RESOLUTION_2048X1536 2
|
||||
|
||||
/* If you want to switch design resolution, change next line */
|
||||
#define TARGET_DESIGN_RESOLUTION_SIZE DESIGN_RESOLUTION_480X320
|
||||
|
||||
typedef struct tagResource
|
||||
{
|
||||
cocos2d::Size size;
|
||||
char directory[100];
|
||||
}Resource;
|
||||
|
||||
static Resource smallResource = { cocos2d::Size(480, 320), "iphone" };
|
||||
static Resource mediumResource = { cocos2d::Size(1024, 768), "ipad" };
|
||||
static Resource largeResource = { cocos2d::Size(2048, 1536), "ipadhd" };
|
||||
|
||||
#if (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_480X320)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(480, 320);
|
||||
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_1024X768)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(1024, 768);
|
||||
#elif (TARGET_DESIGN_RESOLUTION_SIZE == DESIGN_RESOLUTION_2048X1536)
|
||||
static cocos2d::Size designResolutionSize = cocos2d::Size(2048, 1536);
|
||||
#else
|
||||
#error unknown target design resolution!
|
||||
#endif
|
||||
|
||||
// The font size 24 is designed for small resolution, so we should change it to fit for current design resolution
|
||||
#define TITLE_FONT_SIZE (cocos2d::Director::getInstance()->getOpenGLView()->getDesignResolutionSize().width / smallResource.size.width * 24)
|
||||
|
||||
#endif /* __APPMACROS_H__ */
|
|
@ -0,0 +1,266 @@
|
|||
#include "GameControllerTest.h"
|
||||
#include "AppMacros.h"
|
||||
#include "nslog/CCNSLog.h"
|
||||
#include "ui/CocosGUI.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
|
||||
Scene* GameControllerTest::scene()
|
||||
{
|
||||
auto scene = Scene::create();
|
||||
GameControllerTest *layer = GameControllerTest::create();
|
||||
scene->addChild(layer);
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
GameControllerTest::~GameControllerTest()
|
||||
{
|
||||
Controller::stopDiscoveryController();
|
||||
}
|
||||
|
||||
bool GameControllerTest::init()
|
||||
{
|
||||
if ( !Layer::init() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto visibleSize = Director::getInstance()->getVisibleSize();
|
||||
auto origin = Director::getInstance()->getVisibleOrigin();
|
||||
|
||||
auto tmpPos = Vec2(visibleSize / 2) + origin;
|
||||
_actor = Sprite::create("CloseNormal.png");
|
||||
_actor->setPosition(tmpPos);
|
||||
this->addChild(_actor,10);
|
||||
|
||||
tmpPos.y -= 35;
|
||||
_statusLabel = Label::createWithTTF("status", "fonts/Marker Felt.ttf", 40);
|
||||
_statusLabel->setPosition(tmpPos);
|
||||
this->addChild(_statusLabel, 0, 100);
|
||||
|
||||
tmpPos.y += 65;
|
||||
_leftTriggerLabel = Label::createWithTTF("left trigger", "fonts/Marker Felt.ttf", 40);
|
||||
_leftTriggerLabel->setPosition(tmpPos);
|
||||
this->addChild(_leftTriggerLabel, 0, 100);
|
||||
|
||||
tmpPos.y += 40;
|
||||
_rightTriggerLabel = Label::createWithTTF("right trigger", "fonts/Marker Felt.ttf", 40);
|
||||
_rightTriggerLabel->setPosition(tmpPos);
|
||||
this->addChild(_rightTriggerLabel, 0, 100);
|
||||
|
||||
_listener = EventListenerController::create();
|
||||
_listener->onConnected = [=](Controller* controller, Event* event){
|
||||
CCNSLOG("%p connected", controller);
|
||||
_player1 = controller;
|
||||
_statusLabel->setString("controller connected!");
|
||||
};
|
||||
|
||||
_listener->onDisconnected = [=](Controller* controller, Event* event){
|
||||
CCNSLOG("%p disconnected", controller);
|
||||
_player1 = nullptr;
|
||||
_statusLabel->setString("controller disconnected!");
|
||||
};
|
||||
|
||||
_listener->onButtonPressed = CC_CALLBACK_3(GameControllerTest::onButtonPressed, this);
|
||||
_listener->onButtonReleased = CC_CALLBACK_3(GameControllerTest::onButtonReleased, this);
|
||||
_listener->onAxisValueChanged = CC_CALLBACK_3(GameControllerTest::onAxisValueChanged, this);
|
||||
|
||||
_eventDispatcher->addEventListenerWithSceneGraphPriority(_listener, this);
|
||||
|
||||
Controller::startDiscoveryController();
|
||||
|
||||
auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(GameControllerTest::menuCloseCallback, this));
|
||||
closeItem->setPosition(origin + visibleSize - closeItem->getContentSize() / 2);
|
||||
|
||||
auto menu = Menu::create(closeItem,nullptr);
|
||||
menu->setPosition(Vec2::ZERO);
|
||||
this->addChild(menu);
|
||||
|
||||
//get game pad status in polling mode
|
||||
scheduleUpdate();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void GameControllerTest::onButtonPressed(cocos2d::Controller *controller, cocos2d::ControllerButtonInput *button, cocos2d::Event *event)
|
||||
{
|
||||
CCNSLOG("GameControllerTest::onButtonPressed: %p, %d, %f", button, button->isPressed(), button->getValue());
|
||||
|
||||
if (controller == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_player1 = controller;
|
||||
|
||||
auto gamePad = controller->getGamepad();
|
||||
|
||||
if (button == gamePad->getButtonA())
|
||||
{
|
||||
_statusLabel->setString("button A pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonB())
|
||||
{
|
||||
_statusLabel->setString("button B pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonX())
|
||||
{
|
||||
_statusLabel->setString("button X pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonY())
|
||||
{
|
||||
_statusLabel->setString("button Y pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getUp())
|
||||
{
|
||||
_statusLabel->setString("Dpad up pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getDown())
|
||||
{
|
||||
_statusLabel->setString("Dpad down pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getLeft())
|
||||
{
|
||||
_statusLabel->setString("Dpad left pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getRight())
|
||||
{
|
||||
_statusLabel->setString("Dpad right pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getLeftShoulder())
|
||||
{
|
||||
_statusLabel->setString("Left shoulder pressed!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getRightShoulder())
|
||||
{
|
||||
_statusLabel->setString("Right shoulder pressed!");
|
||||
}
|
||||
}
|
||||
|
||||
void GameControllerTest::onButtonReleased(cocos2d::Controller *controller, cocos2d::ControllerButtonInput *button, cocos2d::Event *event)
|
||||
{
|
||||
CCNSLOG("GameControllerTest::onButtonReleased: %p, %d, %f", button, button->isPressed(), button->getValue());
|
||||
|
||||
if (controller == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_player1 = controller;
|
||||
|
||||
auto gamePad = controller->getGamepad();
|
||||
|
||||
if (button == gamePad->getButtonA())
|
||||
{
|
||||
_statusLabel->setString("button A released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonB())
|
||||
{
|
||||
_statusLabel->setString("button B released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonX())
|
||||
{
|
||||
_statusLabel->setString("button X released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getButtonY())
|
||||
{
|
||||
_statusLabel->setString("button Y released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getUp())
|
||||
{
|
||||
_statusLabel->setString("Dpad up released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getDown())
|
||||
{
|
||||
_statusLabel->setString("Dpad down released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getLeft())
|
||||
{
|
||||
_statusLabel->setString("Dpad left released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getDirectionPad()->getRight())
|
||||
{
|
||||
_statusLabel->setString("Dpad right released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getLeftShoulder())
|
||||
{
|
||||
_statusLabel->setString("Left shoulder released!");
|
||||
}
|
||||
|
||||
if (button == gamePad->getRightShoulder())
|
||||
{
|
||||
_statusLabel->setString("Right shoulder released!");
|
||||
}
|
||||
}
|
||||
|
||||
void GameControllerTest::onAxisValueChanged(cocos2d::Controller* controller, cocos2d::ControllerAxisInput* axis, cocos2d::Event* event)
|
||||
{
|
||||
if (controller == nullptr)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_player1 = controller;
|
||||
|
||||
auto moveDelta = axis->getValue();
|
||||
Vec2 newPos = _actor->getPosition();
|
||||
auto gamePad = controller->getGamepad();
|
||||
|
||||
if (axis == gamePad->getLeftThumbstick()->getAxisX() || axis == gamePad->getRightThumbstick()->getAxisX())
|
||||
{
|
||||
newPos.x += moveDelta;
|
||||
}
|
||||
else if (axis == gamePad->getLeftThumbstick()->getAxisY() || axis == gamePad->getRightThumbstick()->getAxisY())
|
||||
{
|
||||
newPos.y -= moveDelta;
|
||||
}
|
||||
_actor->setPosition(newPos);
|
||||
}
|
||||
|
||||
void GameControllerTest::update(float dt)
|
||||
{
|
||||
if (_player1 && _player1->isConnected())
|
||||
{
|
||||
Vec2 newPos = _actor->getPosition();
|
||||
auto gamePad = _player1->getGamepad();
|
||||
|
||||
newPos.x += gamePad->getLeftThumbstick()->getAxisX()->getValue();
|
||||
newPos.y -= gamePad->getLeftThumbstick()->getAxisY()->getValue();
|
||||
|
||||
newPos.x += gamePad->getRightThumbstick()->getAxisX()->getValue();
|
||||
newPos.y -= gamePad->getRightThumbstick()->getAxisY()->getValue();
|
||||
|
||||
_actor->setPosition(newPos);
|
||||
|
||||
char triggerStatus[50];
|
||||
sprintf(triggerStatus,"left trigger:%f",gamePad->getLeftTrigger()->getValue());
|
||||
_leftTriggerLabel->setString(triggerStatus);
|
||||
sprintf(triggerStatus,"right trigger:%f",gamePad->getRightTrigger()->getValue());
|
||||
_rightTriggerLabel->setString(triggerStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void GameControllerTest::menuCloseCallback(Ref* sender)
|
||||
{
|
||||
Director::getInstance()->end();
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||
exit(0);
|
||||
#endif
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
#ifndef __GAMECONTROLLER_TEST_H__
|
||||
#define __GAMECONTROLLER_TEST_H__
|
||||
|
||||
#include "cocos2d.h"
|
||||
#include "base/CCGameController.h"
|
||||
|
||||
class GameControllerTest : public cocos2d::Layer
|
||||
{
|
||||
public:
|
||||
virtual ~GameControllerTest();
|
||||
|
||||
virtual bool init();
|
||||
|
||||
static cocos2d::Scene* scene();
|
||||
|
||||
// a selector callback
|
||||
void menuCloseCallback(Ref* sender);
|
||||
|
||||
// implement the "static node()" method manually
|
||||
CREATE_FUNC(GameControllerTest);
|
||||
|
||||
void update(float dt);
|
||||
void onButtonPressed(cocos2d::Controller* controller, cocos2d::ControllerButtonInput* button, cocos2d::Event* event);
|
||||
void onButtonReleased(cocos2d::Controller* controller, cocos2d::ControllerButtonInput* button, cocos2d::Event* event);
|
||||
void onAxisValueChanged(cocos2d::Controller* controller, cocos2d::ControllerAxisInput* axis, cocos2d::Event* event);
|
||||
private:
|
||||
cocos2d::Controller* _player1;
|
||||
cocos2d::Sprite* _actor;
|
||||
cocos2d::Label* _statusLabel;
|
||||
cocos2d::Label* _leftTriggerLabel;
|
||||
cocos2d::Label* _rightTriggerLabel;
|
||||
cocos2d::EventListenerController* _listener;
|
||||
};
|
||||
|
||||
#endif // __GAMECONTROLLER_TEST_H__
|
|
@ -0,0 +1,2 @@
|
|||
#Do now ignore Marmalade icf files
|
||||
!*.icf
|
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 39 KiB |
After Width: | Height: | Size: 30 KiB |
After Width: | Height: | Size: 6.7 KiB |
After Width: | Height: | Size: 5.6 KiB |
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>GameControllerTest</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>com.android.ide.eclipse.adt.ApkBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<triggers>full,incremental,</triggers>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.core.ccnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,4 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
|
||||
org.eclipse.jdt.core.compiler.compliance=1.6
|
||||
org.eclipse.jdt.core.compiler.source=1.6
|
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.cocos2dx.game_controller_test"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0"
|
||||
android:installLocation="preferExternal">
|
||||
|
||||
<uses-sdk android:minSdkVersion="9"/>
|
||||
<uses-feature android:glEsVersion="0x00020000" />
|
||||
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<!-- Tell Cocos2dxActivity the name of our .so -->
|
||||
<meta-data android:name="android.app.lib_name"
|
||||
android:value="game_controller_test" />
|
||||
|
||||
<activity android:name=".AppActivity"
|
||||
android:label="@string/app_name"
|
||||
android:screenOrientation="landscape"
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
android:configChanges="orientation">
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<supports-screens android:anyDensity="true"
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:xlargeScreens="true"/>
|
||||
</manifest>
|
|
@ -0,0 +1,87 @@
|
|||
## Prerequisites:
|
||||
|
||||
* Android NDK
|
||||
* Android SDK **OR** Eclipse ADT Bundle
|
||||
* Android AVD target installed
|
||||
|
||||
## Building project
|
||||
|
||||
There are two ways of building Android projects.
|
||||
|
||||
1. Eclipse
|
||||
2. Command Line
|
||||
|
||||
### Import Project in Eclipse
|
||||
|
||||
#### Features:
|
||||
|
||||
1. Complete workflow from Eclipse, including:
|
||||
* Build C++.
|
||||
* Clean C++.
|
||||
* Build and Run whole project.
|
||||
* Logcat view.
|
||||
* Debug Java code.
|
||||
* Javascript editor.
|
||||
* Project management.
|
||||
2. True C++ editing, including:
|
||||
* Code completion.
|
||||
* Jump to definition.
|
||||
* Refactoring tools etc.
|
||||
* Quick open C++ files.
|
||||
|
||||
|
||||
#### Setup Eclipse Environment (only once)
|
||||
|
||||
|
||||
**NOTE:** This step needs to be done only once to setup the Eclipse environment for cocos2d-x projects. Skip this section if you've done this before.
|
||||
|
||||
1. Download Eclipse ADT bundle from [Google ADT homepage](http://developer.android.com/sdk/index.html)
|
||||
|
||||
**OR**
|
||||
|
||||
Install Eclipse with Java. Add ADT and CDT plugins.
|
||||
|
||||
2. Only for Windows
|
||||
1. Install [Cygwin](http://www.cygwin.com/) with make (select make package from the list during the install).
|
||||
2. Add `Cygwin\bin` directory to system PATH variable.
|
||||
3. Add this line `none /cygdrive cygdrive binary,noacl,posix=0,user 0 0` to `Cygwin\etc\fstab` file.
|
||||
|
||||
3. Set up Variables:
|
||||
1. Path Variable `COCOS2DX`:
|
||||
* Eclipse->Preferences->General->Workspace->**Linked Resources**
|
||||
* Click **New** button to add a Path Variable `COCOS2DX` pointing to the root cocos2d-x directory.
|
||||
![Example](https://lh5.googleusercontent.com/-oPpk9kg3e5w/UUOYlq8n7aI/AAAAAAAAsdQ/zLA4eghBH9U/s400/cocos2d-x-eclipse-vars.png)
|
||||
|
||||
2. C/C++ Environment Variable `NDK_ROOT`:
|
||||
* Eclipse->Preferences->C/C++->Build->**Environment**.
|
||||
* Click **Add** button and add a new variable `NDK_ROOT` pointing to the root NDK directory.
|
||||
![Example](https://lh3.googleusercontent.com/-AVcY8IAT0_g/UUOYltoRobI/AAAAAAAAsdM/22D2J9u3sig/s400/cocos2d-x-eclipse-ndk.png)
|
||||
* Only for Windows: Add new variables **CYGWIN** with value `nodosfilewarning` and **SHELLOPTS** with value `igncr`
|
||||
|
||||
4. Import libcocos2dx library project:
|
||||
1. File->New->Project->Android Project From Existing Code.
|
||||
2. Click **Browse** button and open `cocos2d-x/cocos2dx/platform/android/java` directory.
|
||||
3. Click **Finish** to add project.
|
||||
|
||||
#### Adding and running from Eclipse
|
||||
|
||||
![Example](https://lh3.googleusercontent.com/-SLBOu6e3QbE/UUOcOXYaGqI/AAAAAAAAsdo/tYBY2SylOSM/s288/cocos2d-x-eclipse-project-from-code.png) ![Import](https://lh5.googleusercontent.com/-XzC9Pn65USc/UUOcOTAwizI/AAAAAAAAsdk/4b6YM-oim9Y/s400/cocos2d-x-eclipse-import-project.png)
|
||||
|
||||
1. File->New->Project->Android Project From Existing Code
|
||||
2. **Browse** to your project directory. eg: `cocos2d-x/cocos2dx/samples/Cpp/TestCpp/proj.android/`
|
||||
3. Add the project
|
||||
4. Click **Run** or **Debug** to compile C++ followed by Java and to run on connected device or emulator.
|
||||
|
||||
|
||||
### Running project from Command Line
|
||||
|
||||
$ cd cocos2d-x/samples/Cpp/TestCpp/proj.android/
|
||||
$ export NDK_ROOT=/path/to/ndk
|
||||
$ ./build_native.sh
|
||||
$ ant debug install
|
||||
|
||||
If the last command results in sdk.dir missing error then do:
|
||||
|
||||
$ android list target
|
||||
$ android update project -p . -t (id from step 6)
|
||||
$ android update project -p cocos2d-x/cocos2dx/platform/android/java/ -t (id from step 6)
|
|
@ -0,0 +1,16 @@
|
|||
{
|
||||
"ndk_module_path" :[
|
||||
"../../..",
|
||||
"../../../cocos",
|
||||
"../../../external"
|
||||
],
|
||||
"copy_resources": [
|
||||
{
|
||||
"from": "../Resources",
|
||||
"to": "",
|
||||
"exclude": [
|
||||
"*.gz"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="GameControllerTest" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android' tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The ant.properties file can be created by you. It is only edited by the
|
||||
'android' tool to add properties to it.
|
||||
This is the place to change some Ant specific build properties.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
For other overridable properties, look at the beginning of the rules
|
||||
files in the SDK, at tools/ant/build.xml
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="ant.properties" />
|
||||
|
||||
<!-- The project.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
|
||||
This contains project specific properties such as project target, and library
|
||||
dependencies. Lower level build properties are stored in ant.properties
|
||||
(or in .classpath for Eclipse projects).
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<loadproperties srcFile="project.properties" />
|
||||
|
||||
<!-- quick check on sdk.dir -->
|
||||
<fail
|
||||
message="sdk.dir is missing. Make sure to generate local.properties using 'android update project' or to inject it through an env var"
|
||||
unless="sdk.dir"
|
||||
/>
|
||||
|
||||
|
||||
<!-- extension targets. Uncomment the ones where you want to do custom work
|
||||
in between standard targets -->
|
||||
<!--
|
||||
<target name="-pre-build">
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
</target>
|
||||
|
||||
/* This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir} */
|
||||
<target name="-post-compile">
|
||||
</target>
|
||||
-->
|
||||
|
||||
<!-- Import the actual build file.
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<import> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole content of build.xml
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, replacing the <import> task.
|
||||
- customize to your needs.
|
||||
|
||||
***********************
|
||||
****** IMPORTANT ******
|
||||
***********************
|
||||
In all cases you must update the value of version-tag below to read 'custom' instead of an integer,
|
||||
in order to avoid having your file be overridden by tools such as "android update project"
|
||||
-->
|
||||
<!-- version-tag: 1 -->
|
||||
<import file="${sdk.dir}/tools/ant/build.xml" />
|
||||
|
||||
</project>
|
|
@ -0,0 +1,21 @@
|
|||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
|
||||
LOCAL_MODULE := game_controller_test_shared
|
||||
|
||||
LOCAL_MODULE_FILENAME := libgame_controller_test
|
||||
|
||||
LOCAL_SRC_FILES := main.cpp \
|
||||
../../Classes/AppDelegate.cpp \
|
||||
../../Classes/GameControllerTest.cpp
|
||||
|
||||
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
|
||||
$(LOCAL_PATH)/../../../../external
|
||||
|
||||
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static
|
||||
|
||||
include $(BUILD_SHARED_LIBRARY)
|
||||
|
||||
$(call import-module,.)
|
||||
$(call import-module,audio/android)
|
|
@ -0,0 +1,14 @@
|
|||
APP_STL := gnustl_static
|
||||
|
||||
# add -Wno-literal-suffix to avoid warning: warning: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wliteral-suffix]
|
||||
# in NDK_ROOT/arch-arm/usr/include/sys/cdefs_elf.h:35:28: when using ndk-r9
|
||||
APP_CPPFLAGS := -frtti -std=c++11 -Wno-literal-suffix -fsigned-char
|
||||
|
||||
APP_DEBUG := $(strip $(NDK_DEBUG))
|
||||
ifeq ($(APP_DEBUG),1)
|
||||
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
|
||||
APP_OPTIM := debug
|
||||
else
|
||||
APP_CPPFLAGS += -DNDEBUG
|
||||
APP_OPTIM := release
|
||||
endif
|
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
append_str=' \'
|
||||
|
||||
list_alldir()
|
||||
{
|
||||
for file in $1/*
|
||||
do
|
||||
if [ -f $file ]; then
|
||||
echo $file$append_str | grep .cpp
|
||||
fi
|
||||
|
||||
if [ -d $file ]; then
|
||||
list_alldir $file
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
list_alldir "$1"
|
||||
else
|
||||
list_alldir "."
|
||||
fi
|
|
@ -0,0 +1,16 @@
|
|||
#include "AppDelegate.h"
|
||||
#include "platform/android/jni/JniHelper.h"
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
|
||||
#include "cocos2d.h"
|
||||
|
||||
#define LOG_TAG "main"
|
||||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
|
||||
void cocos_android_app_init (JNIEnv* env, jobject thiz) {
|
||||
LOGD("cocos_android_app_init");
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
APPNAME="GameControllerTest"
|
||||
APP_ANDROID_NAME="org.cocos2dx.game_controller_test"
|
||||
|
||||
if [ -z "${SDK_ROOT+aaa}" ]; then
|
||||
# ... if SDK_ROOT is not set, use "$HOME/bin/android-sdk"
|
||||
SDK_ROOT="$HOME/bin/android-sdk"
|
||||
fi
|
||||
|
||||
if [ -z "${NDK_ROOT+aaa}" ]; then
|
||||
# ... if NDK_ROOT is not set, use "$HOME/bin/android-ndk"
|
||||
NDK_ROOT="$HOME/bin/android-ndk"
|
||||
fi
|
||||
|
||||
if [ -z "${COCOS2DX_ROOT+aaa}" ]; then
|
||||
# ... if COCOS2DX_ROOT is not set
|
||||
# ... find current working directory
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
# ... use paths relative to current directory
|
||||
COCOS2DX_ROOT="$DIR/../../../.."
|
||||
APP_ROOT="$DIR/.."
|
||||
APP_ANDROID_ROOT="$DIR"
|
||||
else
|
||||
APP_ROOT="$COCOS2DX_ROOT/samples/$APPNAME"
|
||||
APP_ANDROID_ROOT="$COCOS2DX_ROOT/samples/$APPNAME/proj.android"
|
||||
fi
|
||||
|
||||
echo "NDK_ROOT = $NDK_ROOT"
|
||||
echo "SDK_ROOT = $SDK_ROOT"
|
||||
echo "COCOS2DX_ROOT = $COCOS2DX_ROOT"
|
||||
echo "APP_ROOT = $APP_ROOT"
|
||||
echo "APP_ANDROID_ROOT = $APP_ANDROID_ROOT"
|
||||
echo "APP_ANDROID_NAME = $APP_ANDROID_NAME"
|
||||
|
||||
echo
|
||||
echo "Killing and restarting ${APP_ANDROID_NAME}"
|
||||
echo
|
||||
|
||||
set -x
|
||||
|
||||
"${SDK_ROOT}"/platform-tools/adb shell am force-stop "${APP_ANDROID_NAME}"
|
||||
|
||||
NDK_MODULE_PATH="${COCOS2DX_ROOT}":"${COCOS2DX_ROOT}"/cocos2dx/platform/third_party/android/prebuilt \
|
||||
"${NDK_ROOT}"/ndk-gdb \
|
||||
--adb="${SDK_ROOT}"/platform-tools/adb \
|
||||
--verbose \
|
||||
--start \
|
||||
--force
|
|
@ -0,0 +1,20 @@
|
|||
# To enable ProGuard in your project, edit project.properties
|
||||
# to define the proguard.config property as described in that file.
|
||||
#
|
||||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in ${sdk.dir}/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the ProGuard
|
||||
# include property in project.properties.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 5.2 KiB |
After Width: | Height: | Size: 7.4 KiB |
|
@ -0,0 +1,85 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="0"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/statusText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/downloaderDashboard"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/statusText"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressAsFraction"
|
||||
style="@android:style/TextAppearance.Small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:text="0MB / 0MB" >
|
||||
</TextView>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressAsPercentage"
|
||||
style="@android:style/TextAppearance.Small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignRight="@+id/progressBar"
|
||||
android:text="0%" />
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/progressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/progressAsFraction"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_weight="1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressAverageSpeed"
|
||||
style="@android:style/TextAppearance.Small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@+id/progressBar"
|
||||
android:layout_marginLeft="5dp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/progressTimeRemaining"
|
||||
style="@android:style/TextAppearance.Small"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignRight="@+id/progressBar"
|
||||
android:layout_below="@+id/progressBar" />
|
||||
</RelativeLayout>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">GameControllerTest</string>
|
||||
</resources>
|
|
@ -0,0 +1,102 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2014 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
package org.cocos2dx.game_controller_test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.cocos2dx.lib.Cocos2dxActivity;
|
||||
import org.cocos2dx.lib.GameControllerHelper.ControllerListener;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
public class AppActivity extends Cocos2dxActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//The standard controller,without doing anything special. e.g: Amazon Fire TV
|
||||
|
||||
//Automatic adaptation for connect controller.
|
||||
//Supported Platform: Nibiru / Moga / Ouya TV
|
||||
//mControllerHelper.setControllerListener(controllerListener);
|
||||
mControllerHelper.connectController();
|
||||
|
||||
//Manually specify an adapter.
|
||||
//setGameControllerInstance(new GameControllerNibiru());
|
||||
//setGameControllerInstance(new GameControllerMoga());
|
||||
//setGameControllerInstance(new GameControllerOuya());
|
||||
}
|
||||
|
||||
ControllerListener controllerListener = new ControllerListener() {
|
||||
|
||||
@Override
|
||||
public void onDownloadConfigStarted() {
|
||||
Log.w("controllerListener", "onDownloadDepsFinished");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadConfigFinished(boolean isSuccess) {
|
||||
//If download failed
|
||||
Log.w("controllerListener", "onDownloadConfigFinished:" + isSuccess);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerDiscoveryStarted() {
|
||||
Log.w("controllerListener", "onControllerDiscoveryStarted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onControllerDiscoveryFinish(ArrayList<BluetoothDevice> devices) {
|
||||
Log.w("controllerListener", "onControllerDiscoveryFinish");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadDepsStarted() {
|
||||
Log.w("controllerListener", "onDownloadDepsStarted");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadDepsProgress(int bytesWritten, int totalSize) {
|
||||
Log.w("controllerListener", "onDownloadDepsProgress");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDownloadDepsFinished(boolean isSuccess) {
|
||||
Log.w("controllerListener", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInstallDriver(String filePath) {
|
||||
Log.w("controllerListener", "onInstallDriver");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConnectController() {
|
||||
Log.w("controllerListener", "onConnectController");
|
||||
}
|
||||
};
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
@class RootViewController;
|
||||
|
||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
||||
UIWindow *window;
|
||||
RootViewController *viewController;
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
@ -0,0 +1,138 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010 cocos2d-x.org
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "AppController.h"
|
||||
#import "cocos2d.h"
|
||||
#import "AppDelegate.h"
|
||||
#import "CCEAGLView.h"
|
||||
#import "RootViewController.h"
|
||||
|
||||
@implementation AppController
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Application lifecycle
|
||||
|
||||
// cocos2d application instance
|
||||
static AppDelegate s_sharedApplication;
|
||||
|
||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
||||
|
||||
// Override point for customization after application launch.
|
||||
|
||||
// Add the view controller's view to the window and display.
|
||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
CCEAGLView *eaglView = [CCEAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup:nil
|
||||
multiSampling:NO
|
||||
numberOfSamples:0];
|
||||
|
||||
// Use RootViewController manage CCEAGLView
|
||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
||||
viewController.wantsFullScreenLayout = YES;
|
||||
viewController.view = eaglView;
|
||||
|
||||
// Set RootViewController to window
|
||||
if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
|
||||
{
|
||||
// warning: addSubView doesn't work on iOS6
|
||||
[window addSubview: viewController.view];
|
||||
}
|
||||
else
|
||||
{
|
||||
// use this method on ios6
|
||||
[window setRootViewController:viewController];
|
||||
}
|
||||
|
||||
[window makeKeyAndVisible];
|
||||
|
||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
||||
|
||||
// IMPORTANT: Setting the GLView should be done after creating the RootViewController
|
||||
cocos2d::GLView *glview = cocos2d::GLView::createWithEAGLView(eaglView);
|
||||
cocos2d::Director::getInstance()->setOpenGLView(glview);
|
||||
|
||||
cocos2d::Application *app = cocos2d::Application::getInstance();
|
||||
app->run();
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationWillResignActive:(UIApplication *)application {
|
||||
/*
|
||||
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
||||
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->pause();
|
||||
}
|
||||
|
||||
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
||||
/*
|
||||
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
||||
*/
|
||||
cocos2d::Director::getInstance()->resume();
|
||||
}
|
||||
|
||||
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
||||
/*
|
||||
Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
||||
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationDidEnterBackground();
|
||||
}
|
||||
|
||||
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
||||
/*
|
||||
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
|
||||
*/
|
||||
cocos2d::Application::getInstance()->applicationWillEnterForeground();
|
||||
}
|
||||
|
||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
||||
/*
|
||||
Called when the application is about to terminate.
|
||||
See also applicationDidEnterBackground:.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
#pragma mark -
|
||||
#pragma mark Memory management
|
||||
|
||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
||||
/*
|
||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 87 KiB |
After Width: | Height: | Size: 567 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 5.3 KiB |
After Width: | Height: | Size: 8.8 KiB |
After Width: | Height: | Size: 8.2 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 12 KiB |
|
@ -0,0 +1,92 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleDevelopmentRegion</key>
|
||||
<string>English</string>
|
||||
<key>CFBundleDisplayName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>${EXECUTABLE_NAME}</string>
|
||||
<key>CFBundleIconFile</key>
|
||||
<string>Icon-57.png</string>
|
||||
<key>CFBundleIconFiles</key>
|
||||
<array>
|
||||
<string>Icon.png</string>
|
||||
<string>Icon@2x.png</string>
|
||||
<string>Icon-57.png</string>
|
||||
<string>Icon-114.png</string>
|
||||
<string>Icon-72.png</string>
|
||||
<string>Icon-144.png</string>
|
||||
</array>
|
||||
<key>CFBundleIcons</key>
|
||||
<dict>
|
||||
<key>CFBundlePrimaryIcon</key>
|
||||
<dict>
|
||||
<key>CFBundleIconFiles</key>
|
||||
<array>
|
||||
<string>Icon-80</string>
|
||||
<string>Icon-58</string>
|
||||
<string>Icon-120</string>
|
||||
<string>Icon.png</string>
|
||||
<string>Icon@2x.png</string>
|
||||
<string>Icon-57.png</string>
|
||||
<string>Icon-114.png</string>
|
||||
<string>Icon-72.png</string>
|
||||
<string>Icon-144.png</string>
|
||||
</array>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>CFBundleIcons~ipad</key>
|
||||
<dict>
|
||||
<key>CFBundlePrimaryIcon</key>
|
||||
<dict>
|
||||
<key>CFBundleIconFiles</key>
|
||||
<array>
|
||||
<string>Icon-58</string>
|
||||
<string>Icon-80</string>
|
||||
<string>Icon-40</string>
|
||||
<string>Icon-100</string>
|
||||
<string>Icon-152</string>
|
||||
<string>Icon-76</string>
|
||||
<string>Icon-120</string>
|
||||
<string>Icon.png</string>
|
||||
<string>Icon@2x.png</string>
|
||||
<string>Icon-57.png</string>
|
||||
<string>Icon-114.png</string>
|
||||
<string>Icon-72.png</string>
|
||||
<string>Icon-144.png</string>
|
||||
</array>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>org.cocos2d-x.${PRODUCT_NAME:rfc1034identifier}</string>
|
||||
<key>CFBundleInfoDictionaryVersion</key>
|
||||
<string>6.0</string>
|
||||
<key>CFBundleName</key>
|
||||
<string>${PRODUCT_NAME}</string>
|
||||
<key>CFBundlePackageType</key>
|
||||
<string>APPL</string>
|
||||
<key>CFBundleShortVersionString</key>
|
||||
<string></string>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>1.0</string>
|
||||
<key>LSRequiresIPhoneOS</key>
|
||||
<true/>
|
||||
<key>UIPrerenderedIcon</key>
|
||||
<true/>
|
||||
<key>UIStatusBarHidden</key>
|
||||
<true/>
|
||||
<key>UISupportedInterfaceOrientations</key>
|
||||
<array>
|
||||
<string>UIInterfaceOrientationLandscapeRight</string>
|
||||
<string>UIInterfaceOrientationLandscapeLeft</string>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
|
@ -0,0 +1,33 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2010 Ricardo Quesada
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
|
||||
@interface RootViewController : UIViewController {
|
||||
|
||||
}
|
||||
- (BOOL)prefersStatusBarHidden;
|
||||
@end
|
|
@ -0,0 +1,97 @@
|
|||
/****************************************************************************
|
||||
Copyright (c) 2010-2011 cocos2d-x.org
|
||||
Copyright (c) 2010 Ricardo Quesada
|
||||
|
||||
http://www.cocos2d-x.org
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
#import "RootViewController.h"
|
||||
|
||||
|
||||
@implementation RootViewController
|
||||
|
||||
/*
|
||||
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
|
||||
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
||||
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
||||
// Custom initialization
|
||||
}
|
||||
return self;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Implement loadView to create a view hierarchy programmatically, without using a nib.
|
||||
- (void)loadView {
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
*/
|
||||
// Override to allow orientations other than the default portrait orientation.
|
||||
// This method is deprecated on ios6
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
||||
}
|
||||
|
||||
// For ios6.0 and higher, use supportedInterfaceOrientations & shouldAutorotate instead
|
||||
- (NSUInteger) supportedInterfaceOrientations
|
||||
{
|
||||
#ifdef __IPHONE_6_0
|
||||
return UIInterfaceOrientationMaskAllButUpsideDown;
|
||||
#endif
|
||||
}
|
||||
|
||||
- (BOOL) shouldAutorotate {
|
||||
return YES;
|
||||
}
|
||||
|
||||
//fix not hide status on ios7
|
||||
- (BOOL)prefersStatusBarHidden
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)didReceiveMemoryWarning {
|
||||
// Releases the view if it doesn't have a superview.
|
||||
[super didReceiveMemoryWarning];
|
||||
|
||||
// Release any cached data, images, etc that aren't in use.
|
||||
}
|
||||
|
||||
- (void)viewDidUnload {
|
||||
[super viewDidUnload];
|
||||
// Release any retained subviews of the main view.
|
||||
// e.g. self.myOutlet = nil;
|
||||
}
|
||||
|
||||
|
||||
- (void)dealloc {
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
@end
|
|
@ -0,0 +1,17 @@
|
|||
//
|
||||
// main.m
|
||||
// iphone
|
||||
//
|
||||
// Created by Walzer on 10-11-16.
|
||||
// Copyright 2010 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
|
||||
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
|
||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
||||
[pool release];
|
||||
return retVal;
|
||||
}
|