mirror of https://github.com/axmolengine/axmol.git
Merge branch 'master' of https://github.com/cocos2d/cocos2d-x into iss984_bada_qnx_static_lib
This commit is contained in:
commit
05bf647ec3
|
@ -1,191 +0,0 @@
|
||||||
# Cocos2d-x \*NEW\* Lua Engine README
|
|
||||||
|
|
||||||
## Main features
|
|
||||||
|
|
||||||
* Support autorelease CCObject object.
|
|
||||||
* Call Lua function from C++ (local, global, closure), avoid memory leaks.
|
|
||||||
* Add CCNode:setPosition(x, y), CCNode::getPosition() huge performance boost.
|
|
||||||
* Remove needless class and functions from tolua++ .pkg files, improved performance.
|
|
||||||
* CCMenuItem script callback.
|
|
||||||
* CCNode onEnter/onExit events handler.
|
|
||||||
* CCLayer touch & multi-touches events handler.
|
|
||||||
* Build-in Lua modules: cjson, luasocket.
|
|
||||||
|
|
||||||
|
|
||||||
## Changes
|
|
||||||
|
|
||||||
* [del] remove old script support from all
|
|
||||||
* [add] ccConfig.h, define CC_LUA_ENGINE_ENABLED, CC_LUA_ENGINE_DEBUG macro
|
|
||||||
* [add] CCPlatformMacros.h, define LUALOG macro
|
|
||||||
* [add] CCObject::m_uLuaID used for Lua VM tracking C++ object
|
|
||||||
* [add] CCObject::~CCObject() call CCLuaEngine::removeCCObjectByID()
|
|
||||||
* [add] CCNode add some methods for fast read/write position
|
|
||||||
const CCPoint& getPositionLua(void);
|
|
||||||
void getPosition(float* x, float* y);
|
|
||||||
float getPositionX(void);
|
|
||||||
float getPositionY(void);
|
|
||||||
void setPositionX(float x);
|
|
||||||
void setPositionY(float y);
|
|
||||||
void setPosition(float x, float y);
|
|
||||||
void setPositionInPixels(float x, float y);
|
|
||||||
* [add] CCNode::getChildrenCount() for Lua
|
|
||||||
* [add] CCNode::registerScriptHandler() enable onEnter/onExit event script callback
|
|
||||||
* [add] CCNode::unregisterScriptHandler()
|
|
||||||
* [add] CCMenuItem::registerScriptHandler()
|
|
||||||
* [add] CCMenuItem::unregisterScriptHandler()
|
|
||||||
* [add] CCMenuItem::activate() default implements call script callback if exist
|
|
||||||
* [add] CCMenuItem::m_uScriptHandlerFuncID save Lua function reference
|
|
||||||
* [add] CCLayer::m_uScriptHandlerFuncID save Lua function reference
|
|
||||||
* [add] ccTouchBegan(), ccTouchMoved(), ccTouchEnded(), ccTouchCancelled(),
|
|
||||||
ccTouchesBegan(), ccTouchesMoved(), ccTouchesEnded(), ccTouchesCancelled()
|
|
||||||
default implements are used to call script callback if exist
|
|
||||||
* [add] CCLayer::registerScriptTouchHandler()
|
|
||||||
* [add] CCLayer::unregisterScriptTouchHandler()
|
|
||||||
* [add] CCTimer::timerWithScriptFuncID()
|
|
||||||
* [add] CCTimer::initWithScriptFuncID()
|
|
||||||
* [add] CCTimer::m_uScriptFuncID
|
|
||||||
* [add] CCScheduler::scheduleScriptFunc()
|
|
||||||
* [add] CCScheduler::unscheduleScriptEntry()
|
|
||||||
* [add] CCScheduler::m_pScriptEntries
|
|
||||||
* [add] add Lua module: cjson, luasocket
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
## How to use
|
|
||||||
|
|
||||||
### CCNode onEnter/onExit events handler
|
|
||||||
|
|
||||||
CCNode:registerScriptHandler() register callback function for onEnter/onExit events。Callback function auto unregister after onExit() called.
|
|
||||||
|
|
||||||
local function createScene()
|
|
||||||
local scene = CCScene:node()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function sceneEventHandler(eventType)
|
|
||||||
if eventType == kCCNodeOnEnter then
|
|
||||||
if scene.onEnter then scene:onEnter() end
|
|
||||||
else
|
|
||||||
if scene.onExit then scene:onExit() end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
scene:registerScriptHandler(sceneEventHandler)
|
|
||||||
|
|
||||||
return scene
|
|
||||||
end
|
|
||||||
|
|
||||||
local scene = createScene()
|
|
||||||
function scene:onEnter()
|
|
||||||
print("on scene enter")
|
|
||||||
end
|
|
||||||
fucntion scene:onExit()
|
|
||||||
print("on scene exit")
|
|
||||||
end
|
|
||||||
|
|
||||||
CCDirector:sharedDirector():runWithScene(scene)
|
|
||||||
|
|
||||||
|
|
||||||
### Touch and multi-touches events handler
|
|
||||||
|
|
||||||
local function onTouch(eventType, x, y)
|
|
||||||
-- eventType is CCTOUCHBEGAN, CCTOUCHMOVED,
|
|
||||||
-- CCTOUCHENDED or CCTOUCHCANCELLED
|
|
||||||
-- x, y is touch position (use cocos2d-x/OpenGL coordinate)
|
|
||||||
end
|
|
||||||
|
|
||||||
local function onTouches(eventType, touches)
|
|
||||||
-- touches is x1, y1, x2, y2, x3, y3, ...
|
|
||||||
for i = 1, #touches, 2 do
|
|
||||||
local x, y = touches[i], touches[i + 1]
|
|
||||||
print(x, y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local layer = CCLayer:node()
|
|
||||||
|
|
||||||
-- enable touch events callback
|
|
||||||
layer:registerScriptTouchHandler(onTouch, false) -- for single touch
|
|
||||||
OR
|
|
||||||
layer:registerScriptTouchHandler(onTouches, true) -- for multi-touches
|
|
||||||
|
|
||||||
-- remove touch events callback
|
|
||||||
layer:unregisterScriptTouchHandler()
|
|
||||||
|
|
||||||
|
|
||||||
### Schedule callback
|
|
||||||
|
|
||||||
scheduler module:
|
|
||||||
|
|
||||||
module("scheduler", package.seeall)
|
|
||||||
|
|
||||||
scheduler = CCScheduler:sharedScheduler()
|
|
||||||
|
|
||||||
function enterFrame(listener, isPaused)
|
|
||||||
return scheduler:scheduleScriptFunc(listener, 0, isPaused or false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function schedule(listener, interval, isPaused)
|
|
||||||
return scheduler:scheduleScriptFunc(listener, interval, isPaused or false)
|
|
||||||
end
|
|
||||||
|
|
||||||
function unschedule(handle)
|
|
||||||
scheduler:unscheduleScriptEntry(handle)
|
|
||||||
end
|
|
||||||
remove = unschedule
|
|
||||||
|
|
||||||
function performWithDelay(time, listener)
|
|
||||||
local handle
|
|
||||||
handle = scheduler:scheduleScriptFunc(function()
|
|
||||||
scheduler:unscheduleScriptEntry(handle)
|
|
||||||
listener()
|
|
||||||
end, time, false)
|
|
||||||
return handle
|
|
||||||
end
|
|
||||||
|
|
||||||
use:
|
|
||||||
|
|
||||||
require("scheduler")
|
|
||||||
|
|
||||||
local handle -- save script callback ID
|
|
||||||
|
|
||||||
-- schedule every frame update
|
|
||||||
local frameCount = 0
|
|
||||||
local function onEnterFrame(dt)
|
|
||||||
-- dt is float number
|
|
||||||
frameCount = frameCount + 1
|
|
||||||
if frameCount >= 60 then
|
|
||||||
-- unschedule callback
|
|
||||||
scheduler.unschedule(handle)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
handle = scheduler.enterFrame(onEnterFrame)
|
|
||||||
|
|
||||||
-- print message after delay
|
|
||||||
scheduler.performWithDelay(0.5, function()
|
|
||||||
print("delay 0.5 second")
|
|
||||||
end)
|
|
||||||
|
|
||||||
|
|
||||||
### Create menu
|
|
||||||
|
|
||||||
local function onPlayButtonTap()
|
|
||||||
print("PLAY NOW")
|
|
||||||
end
|
|
||||||
|
|
||||||
local button = CCMenuItemSprite:itemFromNormalImage("playButton.png", "playButton.png")
|
|
||||||
button:setPosition(100, 200)
|
|
||||||
button:registerScriptHandler(onPlayButtonTap)
|
|
||||||
|
|
||||||
local menu = CCMenu:node()
|
|
||||||
menu:addChild(button)
|
|
||||||
scene:addChild(menu)
|
|
||||||
|
|
||||||
----
|
|
||||||
|
|
||||||
|
|
||||||
## TODO
|
|
||||||
|
|
||||||
* When C++ object deleted, remove Lua userdata
|
|
||||||
* Improvement tolua_isusertype()
|
|
|
@ -778,6 +778,12 @@ bool CCDirector::enableRetinaDisplay(bool enabled)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SD device
|
||||||
|
if (m_pobOpenGLView->getMainScreenScale() == 1.0)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
float newScale = (float)(enabled ? 2 : 1);
|
float newScale = (float)(enabled ? 2 : 1);
|
||||||
setContentScaleFactor(newScale);
|
setContentScaleFactor(newScale);
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ namespace cocos2d {
|
||||||
|
|
||||||
const char* cocos2dVersion()
|
const char* cocos2dVersion()
|
||||||
{
|
{
|
||||||
return "cocos2d-1.0.1-x-0.11.0";
|
return "cocos2d-1.0.1-x-0.12.0";
|
||||||
}
|
}
|
||||||
|
|
||||||
}//namespace cocos2d
|
}//namespace cocos2d
|
||||||
|
|
|
@ -63,6 +63,8 @@ public:
|
||||||
float getScreenScaleFactor();
|
float getScreenScaleFactor();
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
|
float getMainScreenScale() { return -1.0; }
|
||||||
|
|
||||||
// static function
|
// static function
|
||||||
/**
|
/**
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
|
|
|
@ -72,6 +72,8 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCEGLView& sharedOpenGLView();
|
static CCEGLView& sharedOpenGLView();
|
||||||
|
|
||||||
|
float getMainScreenScale() { return -1.0; }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* param
|
* param
|
||||||
* width[in]: resource width
|
* width[in]: resource width
|
||||||
|
|
|
@ -56,6 +56,8 @@ public:
|
||||||
void touchesEnded(CCSet *set);
|
void touchesEnded(CCSet *set);
|
||||||
void touchesCancelled(CCSet *set);
|
void touchesCancelled(CCSet *set);
|
||||||
|
|
||||||
|
float getMainScreenScale();
|
||||||
|
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
static CCEGLView& sharedOpenGLView();
|
static CCEGLView& sharedOpenGLView();
|
||||||
|
|
|
@ -54,8 +54,7 @@ bool CCEGLView::isOpenGLReady()
|
||||||
|
|
||||||
bool CCEGLView::canSetContentScaleFactor()
|
bool CCEGLView::canSetContentScaleFactor()
|
||||||
{
|
{
|
||||||
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)]
|
return [[EAGLView sharedEGLView] respondsToSelector:@selector(setContentScaleFactor:)];
|
||||||
&& [[UIScreen mainScreen] scale] != 1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
void CCEGLView::setContentScaleFactor(float contentScaleFactor)
|
||||||
|
@ -139,4 +138,9 @@ CCEGLView& CCEGLView::sharedOpenGLView()
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float CCEGLView::getMainScreenScale()
|
||||||
|
{
|
||||||
|
return [[UIScreen mainScreen] scale];
|
||||||
|
}
|
||||||
|
|
||||||
} // end of namespace cocos2d;
|
} // end of namespace cocos2d;
|
||||||
|
|
|
@ -48,6 +48,8 @@ public:
|
||||||
void setViewPortInPoints(float x, float y, float w, float h);
|
void setViewPortInPoints(float x, float y, float w, float h);
|
||||||
void setScissorInPoints(float x, float y, float w, float h);
|
void setScissorInPoints(float x, float y, float w, float h);
|
||||||
|
|
||||||
|
float getMainScreenScale() { return -1.0; }
|
||||||
|
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
// void resize(int width, int height);
|
// void resize(int width, int height);
|
||||||
|
|
|
@ -68,6 +68,8 @@ public:
|
||||||
CCRect getViewPort();
|
CCRect getViewPort();
|
||||||
float getScreenScaleFactor();
|
float getScreenScaleFactor();
|
||||||
|
|
||||||
|
float getMainScreenScale() { return -1.0; }
|
||||||
|
|
||||||
// static function
|
// static function
|
||||||
/**
|
/**
|
||||||
@brief get the shared main open gl window
|
@brief get the shared main open gl window
|
||||||
|
|
|
@ -67,6 +67,8 @@ public:
|
||||||
float getScreenScaleFactor();
|
float getScreenScaleFactor();
|
||||||
void setIMEKeyboardState(bool bOpen);
|
void setIMEKeyboardState(bool bOpen);
|
||||||
|
|
||||||
|
float getMainScreenScale() { return 1.0 };
|
||||||
|
|
||||||
bool HandleEvents();
|
bool HandleEvents();
|
||||||
|
|
||||||
// static function
|
// static function
|
||||||
|
|
|
@ -53,6 +53,8 @@ public:
|
||||||
bool canSetContentScaleFactor();
|
bool canSetContentScaleFactor();
|
||||||
void setContentScaleFactor(float contentScaleFactor);
|
void setContentScaleFactor(float contentScaleFactor);
|
||||||
|
|
||||||
|
float getMainScreenScale() { return -1.0; }
|
||||||
|
|
||||||
virtual bool Create(LPCTSTR pTitle, int w, int h);
|
virtual bool Create(LPCTSTR pTitle, int w, int h);
|
||||||
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
|
virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
echo 'cocos2d-x template installer'
|
echo 'cocos2d-x template installer'
|
||||||
|
|
||||||
COCOS2D_VER='cocos2d-1.0.1-x-0.11.0'
|
COCOS2D_VER='cocos2d-1.0.1-x-0.12.0'
|
||||||
BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode"
|
BASE_TEMPLATE_DIR="/Library/Application Support/Developer/Shared/Xcode"
|
||||||
BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode"
|
BASE_TEMPLATE_USER_DIR="$HOME/Library/Application Support/Developer/Shared/Xcode"
|
||||||
|
|
||||||
|
@ -329,27 +329,4 @@ copy_xcode4_project_templates(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
select_template_version(){
|
|
||||||
echo "select the template version to install"
|
|
||||||
echo "3 for xcode3"
|
|
||||||
echo "4 for xcode4"
|
|
||||||
echo "input nothing for all"
|
|
||||||
|
|
||||||
read select
|
|
||||||
|
|
||||||
if [[ "$select" == 3 ]]; then
|
|
||||||
copy_xcode3_project_templates
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$select" == 4 ]]; then
|
|
||||||
copy_xcode4_project_templates
|
copy_xcode4_project_templates
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$select""aaaa" == "aaaa" ]]; then
|
|
||||||
copy_xcode3_project_templates
|
|
||||||
copy_xcode4_project_templates
|
|
||||||
fi
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
select_template_version
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "AppDelegate.h"
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
USING_NS_CC;
|
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
|
||||||
{
|
|
||||||
bool bRet = false;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView * pMainWnd = new CCEGLView();
|
|
||||||
CC_BREAK_IF(! pMainWnd
|
|
||||||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480));
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WIN32
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
|
||||||
#endif // CC_PLATFORM_IOS
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
||||||
// android does not do anything
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView* pMainWnd = new CCEGLView(this);
|
|
||||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480));
|
|
||||||
|
|
||||||
#ifndef _TRANZDA_VM_
|
|
||||||
// on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
|
|
||||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
|
||||||
|
|
||||||
bRet = true;
|
|
||||||
} while (0);
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::applicationDidFinishLaunching()
|
|
||||||
{
|
|
||||||
// initialize director
|
|
||||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
|
||||||
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
|
||||||
|
|
||||||
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
|
||||||
// pDirector->enableRetinaDisplay(true);
|
|
||||||
|
|
||||||
// sets landscape mode
|
|
||||||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
||||||
|
|
||||||
// turn on display FPS
|
|
||||||
pDirector->setDisplayFPS(true);
|
|
||||||
|
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
|
||||||
|
|
||||||
// create a scene. it's an autorelease object
|
|
||||||
CCScene *pScene = HelloWorld::scene();
|
|
||||||
|
|
||||||
// run
|
|
||||||
pDirector->runWithScene(pScene);
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->pause();
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->resume();
|
|
||||||
|
|
||||||
// if you use SimpleAudioEngine, it must resume here
|
|
||||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef _APP_DELEGATE_H_
|
|
||||||
#define _APP_DELEGATE_H_
|
|
||||||
|
|
||||||
#include "CCApplication.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief The cocos2d Application.
|
|
||||||
|
|
||||||
The reason for implement as private inheritance is to hide some interface call by CCDirector.
|
|
||||||
*/
|
|
||||||
class AppDelegate : private cocos2d::CCApplication
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AppDelegate();
|
|
||||||
virtual ~AppDelegate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement for initialize OpenGL instance, set source path, etc...
|
|
||||||
*/
|
|
||||||
virtual bool initInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement CCDirector and CCScene 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_
|
|
||||||
|
|
|
@ -1,86 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
USING_NS_CC;
|
|
||||||
|
|
||||||
CCScene* HelloWorld::scene()
|
|
||||||
{
|
|
||||||
// 'scene' is an autorelease object
|
|
||||||
CCScene *scene = CCScene::node();
|
|
||||||
|
|
||||||
// 'layer' is an autorelease object
|
|
||||||
HelloWorld *layer = HelloWorld::node();
|
|
||||||
|
|
||||||
// add layer as a child to scene
|
|
||||||
scene->addChild(layer);
|
|
||||||
|
|
||||||
// return the scene
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
// on "init" you need to initialize your instance
|
|
||||||
bool HelloWorld::init()
|
|
||||||
{
|
|
||||||
//////////////////////////////
|
|
||||||
// 1. super init first
|
|
||||||
if ( !CCLayer::init() )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////////////
|
|
||||||
// 2. add a menu item with "X" image, which is clicked to quit the program
|
|
||||||
// you may modify it.
|
|
||||||
|
|
||||||
// add a "close" icon to exit the progress. it's an autorelease object
|
|
||||||
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
|
|
||||||
"CloseNormal.png",
|
|
||||||
"CloseSelected.png",
|
|
||||||
this,
|
|
||||||
menu_selector(HelloWorld::menuCloseCallback) );
|
|
||||||
pCloseItem->setPosition( ccp(CCDirector::sharedDirector()->getWinSize().width - 20, 20) );
|
|
||||||
|
|
||||||
// create menu, it's an autorelease object
|
|
||||||
CCMenu* pMenu = CCMenu::menuWithItems(pCloseItem, NULL);
|
|
||||||
pMenu->setPosition( CCPointZero );
|
|
||||||
this->addChild(pMenu, 1);
|
|
||||||
|
|
||||||
/////////////////////////////
|
|
||||||
// 3. add your codes below...
|
|
||||||
|
|
||||||
// add a label shows "Hello World"
|
|
||||||
// create and initialize a label
|
|
||||||
CCLabelTTF* pLabel = CCLabelTTF::labelWithString("Hello World", "Thonburi", 34);
|
|
||||||
|
|
||||||
// ask director the window size
|
|
||||||
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
||||||
|
|
||||||
// position the label on the center of the screen
|
|
||||||
pLabel->setPosition( ccp(size.width / 2, size.height - 20) );
|
|
||||||
|
|
||||||
// add the label as a child to this layer
|
|
||||||
this->addChild(pLabel, 1);
|
|
||||||
|
|
||||||
// add "HelloWorld" splash screen"
|
|
||||||
CCSprite* pSprite = CCSprite::spriteWithFile("HelloWorld.png");
|
|
||||||
|
|
||||||
// position the sprite on the center of the screen
|
|
||||||
pSprite->setPosition( ccp(size.width/2, size.height/2) );
|
|
||||||
|
|
||||||
// add the sprite as a child to this layer
|
|
||||||
this->addChild(pSprite, 0);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::menuCloseCallback(CCObject* pSender)
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->end();
|
|
||||||
}
|
|
|
@ -1,30 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef __HELLOWORLD_SCENE_H__
|
|
||||||
#define __HELLOWORLD_SCENE_H__
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
|
|
||||||
class HelloWorld : public cocos2d::CCLayer
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
// Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
|
|
||||||
virtual bool init();
|
|
||||||
|
|
||||||
// there's no 'id' in cpp, so we recommand to return the exactly class pointer
|
|
||||||
static cocos2d::CCScene* scene();
|
|
||||||
|
|
||||||
// a selector callback
|
|
||||||
virtual void menuCloseCallback(CCObject* pSender);
|
|
||||||
|
|
||||||
// implement the "static node()" method manually
|
|
||||||
LAYER_NODE_FUNC(HelloWorld);
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __HELLOWORLD_SCENE_H__
|
|
|
@ -1,22 +0,0 @@
|
||||||
cocos2d-x http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Copyright (c) 2008-2010 - (see each file to see the different copyright owners)
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,8 +0,0 @@
|
||||||
//
|
|
||||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#endif
|
|
|
@ -1 +0,0 @@
|
||||||
5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
60686646874bc76241984a6df8beeaa3673f934e
|
|
|
@ -1,17 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@class RootViewController;
|
|
||||||
|
|
||||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
|
||||||
UIWindow *window;
|
|
||||||
RootViewController *viewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import "AppController.h"
|
|
||||||
#import "cocos2d.h"
|
|
||||||
#import "EAGLView.h"
|
|
||||||
#import "AppDelegate.h"
|
|
||||||
|
|
||||||
#import "RootViewController.h"
|
|
||||||
|
|
||||||
@implementation AppController
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Application lifecycle
|
|
||||||
|
|
||||||
// cocos2d application instance
|
|
||||||
static AppDelegate s_sharedApplication;
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
||||||
|
|
||||||
// Override point for customization after application launch.
|
|
||||||
|
|
||||||
// Add the view controller's view to the window and display.
|
|
||||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
|
||||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
|
||||||
pixelFormat: kEAGLColorFormatRGBA8
|
|
||||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
|
||||||
preserveBackbuffer: NO
|
|
||||||
sharegroup: nil
|
|
||||||
multiSampling: NO
|
|
||||||
numberOfSamples: 0 ];
|
|
||||||
|
|
||||||
// Use RootViewController manage EAGLView
|
|
||||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
|
||||||
viewController.wantsFullScreenLayout = YES;
|
|
||||||
viewController.view = __glView;
|
|
||||||
|
|
||||||
// Set RootViewController to window
|
|
||||||
[window addSubview: viewController.view];
|
|
||||||
[window makeKeyAndVisible];
|
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
|
||||||
|
|
||||||
cocos2d::CCApplication::sharedApplication().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::CCDirector::sharedDirector()->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::CCDirector::sharedDirector()->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::CCApplication::sharedApplication().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::CCApplication::sharedApplication().applicationWillEnterForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Called when the application is about to terminate.
|
|
||||||
See also applicationDidEnterBackground:.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Memory management
|
|
||||||
|
|
||||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
|
||||||
*/
|
|
||||||
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
|
|
||||||
@interface RootViewController : UIViewController {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,61 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#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.
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
||||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
|
||||||
}
|
|
||||||
|
|
||||||
- (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
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// main.m
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
||||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
|
||||||
[pool release];
|
|
||||||
return retVal;
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "AppDelegate.h"
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
USING_NS_CC;
|
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
|
||||||
{
|
|
||||||
bool bRet = false;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView * pMainWnd = new CCEGLView();
|
|
||||||
CC_BREAK_IF(! pMainWnd
|
|
||||||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480));
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WIN32
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
|
||||||
#endif // CC_PLATFORM_IOS
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
||||||
// android does not do anything
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView* pMainWnd = new CCEGLView(this);
|
|
||||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480));
|
|
||||||
|
|
||||||
#ifndef _TRANZDA_VM_
|
|
||||||
// on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
|
|
||||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
|
||||||
|
|
||||||
bRet = true;
|
|
||||||
} while (0);
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::applicationDidFinishLaunching()
|
|
||||||
{
|
|
||||||
// initialize director
|
|
||||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
|
||||||
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
|
||||||
|
|
||||||
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
|
||||||
// pDirector->enableRetinaDisplay(true);
|
|
||||||
|
|
||||||
// sets landscape mode
|
|
||||||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
||||||
|
|
||||||
// turn on display FPS
|
|
||||||
pDirector->setDisplayFPS(true);
|
|
||||||
|
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
|
||||||
|
|
||||||
// create a scene. it's an autorelease object
|
|
||||||
CCScene *pScene = HelloWorld::scene();
|
|
||||||
|
|
||||||
// run
|
|
||||||
pDirector->runWithScene(pScene);
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->pause();
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->resume();
|
|
||||||
|
|
||||||
// if you use SimpleAudioEngine, it must resume here
|
|
||||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef _APP_DELEGATE_H_
|
|
||||||
#define _APP_DELEGATE_H_
|
|
||||||
|
|
||||||
#include "CCApplication.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief The cocos2d Application.
|
|
||||||
|
|
||||||
The reason for implement as private inheritance is to hide some interface call by CCDirector.
|
|
||||||
*/
|
|
||||||
class AppDelegate : private cocos2d::CCApplication
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AppDelegate();
|
|
||||||
virtual ~AppDelegate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement for initialize OpenGL instance, set source path, etc...
|
|
||||||
*/
|
|
||||||
virtual bool initInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement CCDirector and CCScene 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_
|
|
||||||
|
|
|
@ -1,215 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
using namespace cocos2d;
|
|
||||||
|
|
||||||
#define PTM_RATIO 32
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
kTagTileMap = 1,
|
|
||||||
kTagSpriteManager = 1,
|
|
||||||
kTagAnimation1 = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
HelloWorld::HelloWorld()
|
|
||||||
{
|
|
||||||
setIsTouchEnabled( true );
|
|
||||||
setIsAccelerometerEnabled( true );
|
|
||||||
|
|
||||||
CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
|
|
||||||
//UXLOG(L"Screen width %0.2f screen height %0.2f",screenSize.width,screenSize.height);
|
|
||||||
|
|
||||||
// Define the gravity vector.
|
|
||||||
b2Vec2 gravity;
|
|
||||||
gravity.Set(0.0f, -10.0f);
|
|
||||||
|
|
||||||
// Do we want to let bodies sleep?
|
|
||||||
bool doSleep = true;
|
|
||||||
|
|
||||||
// Construct a world object, which will hold and simulate the rigid bodies.
|
|
||||||
world = new b2World(gravity, doSleep);
|
|
||||||
|
|
||||||
world->SetContinuousPhysics(true);
|
|
||||||
|
|
||||||
/*
|
|
||||||
m_debugDraw = new GLESDebugDraw( PTM_RATIO );
|
|
||||||
world->SetDebugDraw(m_debugDraw);
|
|
||||||
|
|
||||||
uint flags = 0;
|
|
||||||
flags += b2DebugDraw::e_shapeBit;
|
|
||||||
flags += b2DebugDraw::e_jointBit;
|
|
||||||
flags += b2DebugDraw::e_aabbBit;
|
|
||||||
flags += b2DebugDraw::e_pairBit;
|
|
||||||
flags += b2DebugDraw::e_centerOfMassBit;
|
|
||||||
m_debugDraw->SetFlags(flags);
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Define the ground body.
|
|
||||||
b2BodyDef groundBodyDef;
|
|
||||||
groundBodyDef.position.Set(0, 0); // bottom-left corner
|
|
||||||
|
|
||||||
// Call the body factory which allocates memory for the ground body
|
|
||||||
// from a pool and creates the ground box shape (also from a pool).
|
|
||||||
// The body is also added to the world.
|
|
||||||
b2Body* groundBody = world->CreateBody(&groundBodyDef);
|
|
||||||
|
|
||||||
// Define the ground box shape.
|
|
||||||
b2PolygonShape groundBox;
|
|
||||||
|
|
||||||
// bottom
|
|
||||||
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(screenSize.width/PTM_RATIO,0));
|
|
||||||
groundBody->CreateFixture(&groundBox, 0);
|
|
||||||
|
|
||||||
// top
|
|
||||||
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO));
|
|
||||||
groundBody->CreateFixture(&groundBox, 0);
|
|
||||||
|
|
||||||
// left
|
|
||||||
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0));
|
|
||||||
groundBody->CreateFixture(&groundBox, 0);
|
|
||||||
|
|
||||||
// right
|
|
||||||
groundBox.SetAsEdge(b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,0));
|
|
||||||
groundBody->CreateFixture(&groundBox, 0);
|
|
||||||
|
|
||||||
|
|
||||||
//Set up sprite
|
|
||||||
|
|
||||||
CCSpriteBatchNode *mgr = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 150);
|
|
||||||
addChild(mgr, 0, kTagSpriteManager);
|
|
||||||
|
|
||||||
addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) );
|
|
||||||
|
|
||||||
CCLabelTTF *label = CCLabelTTF::labelWithString("Tap screen", "Marker Felt", 32);
|
|
||||||
addChild(label, 0);
|
|
||||||
label->setColor( ccc3(0,0,255) );
|
|
||||||
label->setPosition( CCPointMake( screenSize.width/2, screenSize.height-50) );
|
|
||||||
|
|
||||||
schedule( schedule_selector(HelloWorld::tick) );
|
|
||||||
}
|
|
||||||
|
|
||||||
HelloWorld::~HelloWorld()
|
|
||||||
{
|
|
||||||
delete world;
|
|
||||||
world = NULL;
|
|
||||||
|
|
||||||
//delete m_debugDraw;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::draw()
|
|
||||||
{
|
|
||||||
// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
|
||||||
// Needed states: GL_VERTEX_ARRAY,
|
|
||||||
// Unneeded states: GL_TEXTURE_2D, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
|
|
||||||
glDisable(GL_TEXTURE_2D);
|
|
||||||
glDisableClientState(GL_COLOR_ARRAY);
|
|
||||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
|
|
||||||
//world->DrawDebugData();
|
|
||||||
|
|
||||||
// restore default GL states
|
|
||||||
glEnable(GL_TEXTURE_2D);
|
|
||||||
glEnableClientState(GL_COLOR_ARRAY);
|
|
||||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::addNewSpriteWithCoords(CCPoint p)
|
|
||||||
{
|
|
||||||
//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
|
|
||||||
CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);
|
|
||||||
|
|
||||||
//We have a 64x64 sprite sheet with 4 different 32x32 images. The following code is
|
|
||||||
//just randomly picking one of the images
|
|
||||||
int idx = (CCRANDOM_0_1() > .5 ? 0:1);
|
|
||||||
int idy = (CCRANDOM_0_1() > .5 ? 0:1);
|
|
||||||
CCSprite *sprite = CCSprite::spriteWithBatchNode(sheet, CCRectMake(32 * idx,32 * idy,32,32));
|
|
||||||
sheet->addChild(sprite);
|
|
||||||
|
|
||||||
sprite->setPosition( CCPointMake( p.x, p.y) );
|
|
||||||
|
|
||||||
// Define the dynamic body.
|
|
||||||
//Set up a 1m squared box in the physics world
|
|
||||||
b2BodyDef bodyDef;
|
|
||||||
bodyDef.type = b2_dynamicBody;
|
|
||||||
bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
|
|
||||||
bodyDef.userData = sprite;
|
|
||||||
b2Body *body = world->CreateBody(&bodyDef);
|
|
||||||
|
|
||||||
// Define another box shape for our dynamic body.
|
|
||||||
b2PolygonShape dynamicBox;
|
|
||||||
dynamicBox.SetAsBox(.5f, .5f);//These are mid points for our 1m box
|
|
||||||
|
|
||||||
// Define the dynamic body fixture.
|
|
||||||
b2FixtureDef fixtureDef;
|
|
||||||
fixtureDef.shape = &dynamicBox;
|
|
||||||
fixtureDef.density = 1.0f;
|
|
||||||
fixtureDef.friction = 0.3f;
|
|
||||||
body->CreateFixture(&fixtureDef);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HelloWorld::tick(ccTime dt)
|
|
||||||
{
|
|
||||||
//It is recommended that a fixed time step is used with Box2D for stability
|
|
||||||
//of the simulation, however, we are using a variable time step here.
|
|
||||||
//You need to make an informed choice, the following URL is useful
|
|
||||||
//http://gafferongames.com/game-physics/fix-your-timestep/
|
|
||||||
|
|
||||||
int velocityIterations = 8;
|
|
||||||
int positionIterations = 1;
|
|
||||||
|
|
||||||
// Instruct the world to perform a single step of simulation. It is
|
|
||||||
// generally best to keep the time step and iterations fixed.
|
|
||||||
world->Step(dt, velocityIterations, positionIterations);
|
|
||||||
|
|
||||||
//Iterate over the bodies in the physics world
|
|
||||||
for (b2Body* b = world->GetBodyList(); b; b = b->GetNext())
|
|
||||||
{
|
|
||||||
if (b->GetUserData() != NULL) {
|
|
||||||
//Synchronize the AtlasSprites position and rotation with the corresponding body
|
|
||||||
CCSprite* myActor = (CCSprite*)b->GetUserData();
|
|
||||||
myActor->setPosition( CCPointMake( b->GetPosition().x * PTM_RATIO, b->GetPosition().y * PTM_RATIO) );
|
|
||||||
myActor->setRotation( -1 * CC_RADIANS_TO_DEGREES(b->GetAngle()) );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
|
||||||
{
|
|
||||||
//Add a new body/atlas sprite at the touched location
|
|
||||||
CCSetIterator it;
|
|
||||||
CCTouch* touch;
|
|
||||||
|
|
||||||
for( it = touches->begin(); it != touches->end(); it++)
|
|
||||||
{
|
|
||||||
touch = (CCTouch*)(*it);
|
|
||||||
|
|
||||||
if(!touch)
|
|
||||||
break;
|
|
||||||
|
|
||||||
CCPoint location = touch->locationInView(touch->view());
|
|
||||||
|
|
||||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
|
||||||
|
|
||||||
addNewSpriteWithCoords( location );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CCScene* HelloWorld::scene()
|
|
||||||
{
|
|
||||||
// 'scene' is an autorelease object
|
|
||||||
CCScene *scene = CCScene::node();
|
|
||||||
|
|
||||||
// add layer as a child to scene
|
|
||||||
CCLayer* layer = new HelloWorld();
|
|
||||||
scene->addChild(layer);
|
|
||||||
layer->release();
|
|
||||||
|
|
||||||
return scene;
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
#ifndef __HELLO_WORLD_H__
|
|
||||||
#define __HELLO_WORLD_H__
|
|
||||||
|
|
||||||
// When you import this file, you import all the cocos2d classes
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "Box2D.h"
|
|
||||||
|
|
||||||
class HelloWorld : public cocos2d::CCLayer {
|
|
||||||
public:
|
|
||||||
~HelloWorld();
|
|
||||||
HelloWorld();
|
|
||||||
|
|
||||||
// returns a Scene that contains the HelloWorld as the only child
|
|
||||||
static cocos2d::CCScene* scene();
|
|
||||||
|
|
||||||
// adds a new sprite at a given coordinate
|
|
||||||
void addNewSpriteWithCoords(cocos2d::CCPoint p);
|
|
||||||
virtual void draw();
|
|
||||||
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
|
|
||||||
void tick(cocos2d::ccTime dt);
|
|
||||||
|
|
||||||
private:
|
|
||||||
b2World* world;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __HELLO_WORLD_H__
|
|
|
@ -1,18 +0,0 @@
|
||||||
Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com
|
|
||||||
|
|
||||||
This software is provided 'as-is', without any express or implied
|
|
||||||
warranty. In no event will the authors be held liable for any damages
|
|
||||||
arising from the use of this software.
|
|
||||||
|
|
||||||
Permission is granted to anyone to use this software for any purpose,
|
|
||||||
including commercial applications, and to alter it and redistribute it
|
|
||||||
freely, subject to the following restrictions:
|
|
||||||
|
|
||||||
1. The origin of this software must not be misrepresented; you must not
|
|
||||||
claim that you wrote the original software. If you use this software
|
|
||||||
in a product, an acknowledgment in the product documentation would be
|
|
||||||
appreciated but is not required.
|
|
||||||
2. Altered source versions must be plainly marked as such, and must not be
|
|
||||||
misrepresented as being the original software.
|
|
||||||
3. This notice may not be removed or altered from any source distribution.
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
cocos2d-x http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Copyright (c) 2008-2010 - (see each file to see the different copyright owners)
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,8 +0,0 @@
|
||||||
//
|
|
||||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#endif
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
b8d0b27908d823a2687767793e04c64fe1541def
|
|
|
@ -1,17 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@class RootViewController;
|
|
||||||
|
|
||||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
|
||||||
UIWindow *window;
|
|
||||||
RootViewController *viewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import "AppController.h"
|
|
||||||
#import "cocos2d.h"
|
|
||||||
#import "EAGLView.h"
|
|
||||||
#import "AppDelegate.h"
|
|
||||||
|
|
||||||
#import "RootViewController.h"
|
|
||||||
|
|
||||||
@implementation AppController
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Application lifecycle
|
|
||||||
|
|
||||||
// cocos2d application instance
|
|
||||||
static AppDelegate s_sharedApplication;
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
||||||
|
|
||||||
// Override point for customization after application launch.
|
|
||||||
|
|
||||||
// Add the view controller's view to the window and display.
|
|
||||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
|
||||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
|
||||||
pixelFormat: kEAGLColorFormatRGBA8
|
|
||||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
|
||||||
preserveBackbuffer: NO
|
|
||||||
sharegroup: nil
|
|
||||||
multiSampling: NO
|
|
||||||
numberOfSamples: 0 ];
|
|
||||||
|
|
||||||
// Use RootViewController manage EAGLView
|
|
||||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
|
||||||
viewController.wantsFullScreenLayout = YES;
|
|
||||||
viewController.view = __glView;
|
|
||||||
|
|
||||||
// Set RootViewController to window
|
|
||||||
[window addSubview: viewController.view];
|
|
||||||
[window makeKeyAndVisible];
|
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
|
||||||
|
|
||||||
cocos2d::CCApplication::sharedApplication().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::CCDirector::sharedDirector()->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::CCDirector::sharedDirector()->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::CCApplication::sharedApplication().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::CCApplication::sharedApplication().applicationWillEnterForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Called when the application is about to terminate.
|
|
||||||
See also applicationDidEnterBackground:.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Memory management
|
|
||||||
|
|
||||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
|
||||||
*/
|
|
||||||
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
|
|
||||||
@interface RootViewController : UIViewController {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,61 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#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.
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
||||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
|
||||||
}
|
|
||||||
|
|
||||||
- (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
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// main.m
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
||||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
|
||||||
[pool release];
|
|
||||||
return retVal;
|
|
||||||
}
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#include "AppDelegate.h"
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
USING_NS_CC;
|
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
|
||||||
{
|
|
||||||
bool bRet = false;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView * pMainWnd = new CCEGLView();
|
|
||||||
CC_BREAK_IF(! pMainWnd
|
|
||||||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 320, 480));
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WIN32
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
|
||||||
#endif // CC_PLATFORM_IOS
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
||||||
// android does not do anything
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView* pMainWnd = new CCEGLView(this);
|
|
||||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480));
|
|
||||||
|
|
||||||
#ifndef _TRANZDA_VM_
|
|
||||||
// on wophone emulator, we copy resources files to Work7/TG3/APP/ folder instead of zip file
|
|
||||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
|
||||||
|
|
||||||
bRet = true;
|
|
||||||
} while (0);
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::applicationDidFinishLaunching()
|
|
||||||
{
|
|
||||||
// initialize director
|
|
||||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
|
||||||
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
|
||||||
|
|
||||||
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
|
||||||
// pDirector->enableRetinaDisplay(true);
|
|
||||||
|
|
||||||
// sets landscape mode
|
|
||||||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
||||||
|
|
||||||
// turn on display FPS
|
|
||||||
pDirector->setDisplayFPS(true);
|
|
||||||
|
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
|
||||||
|
|
||||||
// create a scene. it's an autorelease object
|
|
||||||
CCScene *pScene = HelloWorld::scene();
|
|
||||||
|
|
||||||
// run
|
|
||||||
pDirector->runWithScene(pScene);
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->pause();
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->resume();
|
|
||||||
|
|
||||||
// if you use SimpleAudioEngine, it must resume here
|
|
||||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
||||||
}
|
|
|
@ -1,51 +0,0 @@
|
||||||
//
|
|
||||||
// ___PROJECTNAMEASIDENTIFIER___AppDelegate.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef _APP_DELEGATE_H_
|
|
||||||
#define _APP_DELEGATE_H_
|
|
||||||
|
|
||||||
#include "CCApplication.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief The cocos2d Application.
|
|
||||||
|
|
||||||
The reason for implement as private inheritance is to hide some interface call by CCDirector.
|
|
||||||
*/
|
|
||||||
class AppDelegate : private cocos2d::CCApplication
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AppDelegate();
|
|
||||||
virtual ~AppDelegate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement for initialize OpenGL instance, set source path, etc...
|
|
||||||
*/
|
|
||||||
virtual bool initInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement CCDirector and CCScene 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_
|
|
||||||
|
|
|
@ -1,187 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.cpp
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
||||||
#include "HelloWorldScene.h"
|
|
||||||
|
|
||||||
using namespace cocos2d;
|
|
||||||
|
|
||||||
enum {
|
|
||||||
kTagBatchNode = 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
eachShape(void *ptr, void* unused)
|
|
||||||
{
|
|
||||||
cpShape *shape = (cpShape*) ptr;
|
|
||||||
CCSprite *sprite = (CCSprite*)shape->data;
|
|
||||||
if( sprite )
|
|
||||||
{
|
|
||||||
cpBody *body = shape->body;
|
|
||||||
|
|
||||||
// TIP: cocos2d and chipmunk uses the same struct to store it's position
|
|
||||||
// chipmunk uses: cpVect, and cocos2d uses CGPoint but in reality the are the same
|
|
||||||
// since v0.7.1 you can mix them if you want.
|
|
||||||
sprite->setPosition(CCPointMake(body->p.x, body->p.y));
|
|
||||||
|
|
||||||
sprite->setRotation((float) CC_RADIANS_TO_DEGREES( -body->a ));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HelloWorld::HelloWorld()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
HelloWorld::~HelloWorld()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CCScene* HelloWorld::scene()
|
|
||||||
{
|
|
||||||
// 'scene' is an autorelease object.
|
|
||||||
CCScene *scene = CCScene::node();
|
|
||||||
|
|
||||||
// 'layer' is an autorelease object.
|
|
||||||
HelloWorld *layer = HelloWorld::node();
|
|
||||||
|
|
||||||
// add layer as a child to scene
|
|
||||||
scene->addChild(layer);
|
|
||||||
|
|
||||||
// return the scene
|
|
||||||
return scene;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HelloWorld::addNewSpriteX(float x, float y)
|
|
||||||
{
|
|
||||||
int posx, posy;
|
|
||||||
|
|
||||||
CCSpriteBatchNode *batch = (CCSpriteBatchNode*) getChildByTag(kTagBatchNode);
|
|
||||||
|
|
||||||
posx = (CCRANDOM_0_1() * 200);
|
|
||||||
posy = (CCRANDOM_0_1() * 200);
|
|
||||||
|
|
||||||
posx = (posx % 4) * 85;
|
|
||||||
posy = (posy % 3) * 121;
|
|
||||||
|
|
||||||
CCSprite *sprite = CCSprite::spriteWithBatchNode(batch, CCRectMake(posx, posy, 85, 121));
|
|
||||||
batch->addChild(sprite);
|
|
||||||
|
|
||||||
sprite->setPosition(ccp(x, y));
|
|
||||||
|
|
||||||
int num = 4;
|
|
||||||
cpVect verts[] = {
|
|
||||||
cpv(-24,-54),
|
|
||||||
cpv(-24, 54),
|
|
||||||
cpv( 24, 54),
|
|
||||||
cpv( 24,-54),
|
|
||||||
};
|
|
||||||
|
|
||||||
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpv(0, 0)));
|
|
||||||
|
|
||||||
// TIP:
|
|
||||||
// since v0.7.1 you can assign CGPoint to chipmunk instead of cpVect.
|
|
||||||
// cpVect == CGPoint
|
|
||||||
body->p = cpv(x, y);
|
|
||||||
cpSpaceAddBody(space, body);
|
|
||||||
|
|
||||||
cpShape* shape = cpPolyShapeNew(body, num, verts, cpv(0, 0));
|
|
||||||
shape->e = 0.5f; shape->u = 0.5f;
|
|
||||||
shape->data = sprite;
|
|
||||||
cpSpaceAddShape(space, shape);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool HelloWorld::init()
|
|
||||||
{
|
|
||||||
bool ret = false;
|
|
||||||
|
|
||||||
if (ret = CCLayer::init())
|
|
||||||
{
|
|
||||||
setIsTouchEnabled(true);
|
|
||||||
|
|
||||||
CCSize wins = CCDirector::sharedDirector()->getWinSize();
|
|
||||||
cpInitChipmunk();
|
|
||||||
|
|
||||||
cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
|
|
||||||
space = cpSpaceNew();
|
|
||||||
cpSpaceResizeStaticHash(space, 400.0f, 40);
|
|
||||||
cpSpaceResizeActiveHash(space, 100, 600);
|
|
||||||
|
|
||||||
space->gravity = cpv(0, 0);
|
|
||||||
space->elasticIterations = space->iterations;
|
|
||||||
|
|
||||||
cpShape *shape;
|
|
||||||
|
|
||||||
// bottom
|
|
||||||
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(wins.width,0), 0.0f);
|
|
||||||
shape->e = 1.0f; shape->u = 1.0f;
|
|
||||||
cpSpaceAddStaticShape(space, shape);
|
|
||||||
|
|
||||||
// top
|
|
||||||
shape = cpSegmentShapeNew(staticBody, cpv(0,wins.height), cpv(wins.width,wins.height), 0.0f);
|
|
||||||
shape->e = 1.0f; shape->u = 1.0f;
|
|
||||||
cpSpaceAddStaticShape(space, shape);
|
|
||||||
|
|
||||||
// left
|
|
||||||
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(0,wins.height), 0.0f);
|
|
||||||
shape->e = 1.0f; shape->u = 1.0f;
|
|
||||||
cpSpaceAddStaticShape(space, shape);
|
|
||||||
|
|
||||||
// right
|
|
||||||
shape = cpSegmentShapeNew(staticBody, cpv(wins.width,0), cpv(wins.width,wins.height), 0.0f);
|
|
||||||
shape->e = 1.0f; shape->u = 1.0f;
|
|
||||||
cpSpaceAddStaticShape(space, shape);
|
|
||||||
|
|
||||||
CCSpriteBatchNode *batch = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 100);
|
|
||||||
addChild(batch, 0, kTagBatchNode);
|
|
||||||
|
|
||||||
addNewSpriteX(200, 200);
|
|
||||||
|
|
||||||
schedule(schedule_selector(HelloWorld::step));
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::onEnter()
|
|
||||||
{
|
|
||||||
CCLayer::onEnter();
|
|
||||||
}
|
|
||||||
|
|
||||||
void HelloWorld::step(ccTime delta)
|
|
||||||
{
|
|
||||||
int steps = 2;
|
|
||||||
CGFloat dt = delta/(CGFloat)steps;
|
|
||||||
|
|
||||||
for(int i=0; i<steps; i++)
|
|
||||||
{
|
|
||||||
cpSpaceStep(space, dt);
|
|
||||||
}
|
|
||||||
cpSpaceHashEach(space->activeShapes, &eachShape, NULL);
|
|
||||||
cpSpaceHashEach(space->staticShapes, &eachShape, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event)
|
|
||||||
{
|
|
||||||
CCSetIterator it;
|
|
||||||
CCTouch *touch;
|
|
||||||
|
|
||||||
for (it = touches->begin(); it != touches->end(); it++) {
|
|
||||||
touch = (CCTouch*)(*it);
|
|
||||||
|
|
||||||
if (! touch) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
CCPoint location = touch->locationInView(touch->view());
|
|
||||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
|
||||||
addNewSpriteX(location.x, location.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
//
|
|
||||||
// HelloWorldScene.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifndef __HELLOW_WORLD_H__
|
|
||||||
#define __HELLOW_WORLD_H__
|
|
||||||
|
|
||||||
#include "cocos2d.h"
|
|
||||||
|
|
||||||
// include Chipmunk headers
|
|
||||||
#include "chipmunk.h"
|
|
||||||
|
|
||||||
// HelloWorld Layer
|
|
||||||
class HelloWorld : public cocos2d::CCLayer {
|
|
||||||
public:
|
|
||||||
HelloWorld();
|
|
||||||
~HelloWorld();
|
|
||||||
|
|
||||||
static cocos2d::CCScene* scene();
|
|
||||||
void step(cocos2d::ccTime dt);
|
|
||||||
void addNewSpriteX(float x, float y);
|
|
||||||
virtual void onEnter();
|
|
||||||
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent *event);
|
|
||||||
|
|
||||||
LAYER_NODE_FUNC(HelloWorld);
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool init();
|
|
||||||
cpSpace *space;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // __HELLOW_WORLD_H__
|
|
|
@ -1,19 +0,0 @@
|
||||||
Copyright (c) 2007 Scott Lembcke and Howling Moon Software
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,22 +0,0 @@
|
||||||
cocos2d-x http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Copyright (c) 2008-2010 - (see each file to see the different copyright owners)
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,8 +0,0 @@
|
||||||
//
|
|
||||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#endif
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
4df124f68856ca5915635b8392bb8aa85c79259f
|
|
|
@ -1,17 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@class RootViewController;
|
|
||||||
|
|
||||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
|
||||||
UIWindow *window;
|
|
||||||
RootViewController *viewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import "AppController.h"
|
|
||||||
#import "cocos2d.h"
|
|
||||||
#import "EAGLView.h"
|
|
||||||
#import "AppDelegate.h"
|
|
||||||
|
|
||||||
#import "RootViewController.h"
|
|
||||||
|
|
||||||
@implementation AppController
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Application lifecycle
|
|
||||||
|
|
||||||
// cocos2d application instance
|
|
||||||
static AppDelegate s_sharedApplication;
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
||||||
|
|
||||||
// Override point for customization after application launch.
|
|
||||||
|
|
||||||
// Add the view controller's view to the window and display.
|
|
||||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
|
||||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
|
||||||
pixelFormat: kEAGLColorFormatRGBA8
|
|
||||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
|
||||||
preserveBackbuffer: NO
|
|
||||||
sharegroup: nil
|
|
||||||
multiSampling: NO
|
|
||||||
numberOfSamples: 0 ];
|
|
||||||
|
|
||||||
// Use RootViewController manage EAGLView
|
|
||||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
|
||||||
viewController.wantsFullScreenLayout = YES;
|
|
||||||
viewController.view = __glView;
|
|
||||||
|
|
||||||
// Set RootViewController to window
|
|
||||||
[window addSubview: viewController.view];
|
|
||||||
[window makeKeyAndVisible];
|
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
|
||||||
|
|
||||||
cocos2d::CCApplication::sharedApplication().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::CCDirector::sharedDirector()->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::CCDirector::sharedDirector()->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::CCApplication::sharedApplication().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::CCApplication::sharedApplication().applicationWillEnterForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Called when the application is about to terminate.
|
|
||||||
See also applicationDidEnterBackground:.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Memory management
|
|
||||||
|
|
||||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
|
||||||
*/
|
|
||||||
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
|
|
||||||
@interface RootViewController : UIViewController {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,61 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#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.
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
||||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
|
||||||
}
|
|
||||||
|
|
||||||
- (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
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// main.m
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
||||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
|
||||||
[pool release];
|
|
||||||
return retVal;
|
|
||||||
}
|
|
|
@ -1,135 +0,0 @@
|
||||||
|
|
||||||
#include "AppDelegate.h"
|
|
||||||
#include "cocos2d.h"
|
|
||||||
#include "SimpleAudioEngine.h"
|
|
||||||
#include "CCLuaEngine.h"
|
|
||||||
|
|
||||||
USING_NS_CC;
|
|
||||||
using namespace CocosDenshion;
|
|
||||||
|
|
||||||
AppDelegate::AppDelegate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
AppDelegate::~AppDelegate()
|
|
||||||
{
|
|
||||||
// end simple audio engine here, or it may crashed on win32
|
|
||||||
SimpleAudioEngine::sharedEngine()->end();
|
|
||||||
CCLuaEngine::purgeSharedEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::initInstance()
|
|
||||||
{
|
|
||||||
bool bRet = false;
|
|
||||||
do
|
|
||||||
{
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView * pMainWnd = new CCEGLView();
|
|
||||||
CC_BREAK_IF(! pMainWnd
|
|
||||||
|| ! pMainWnd->Create(TEXT("cocos2d: Hello World"), 480, 320));
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WIN32
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
|
|
||||||
// OpenGLView initialized in testsAppDelegate.mm on ios platform, nothing need to do here.
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_IOS
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
||||||
|
|
||||||
// OpenGLView initialized in HelloWorld/android/jni/helloworld/main.cpp
|
|
||||||
// the default setting is to create a fullscreen view
|
|
||||||
// if you want to use auto-scale, please enable view->create(320,480) in main.cpp
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_ANDROID
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WOPHONE)
|
|
||||||
|
|
||||||
// Initialize OpenGLView instance, that release by CCDirector when application terminate.
|
|
||||||
// The HelloWorld is designed as HVGA.
|
|
||||||
CCEGLView* pMainWnd = new CCEGLView(this);
|
|
||||||
CC_BREAK_IF(! pMainWnd || ! pMainWnd->Create(320,480, WM_WINDOW_ROTATE_MODE_CW));
|
|
||||||
|
|
||||||
#ifndef _TRANZDA_VM_
|
|
||||||
// on wophone emulator, we copy resources files to Work7/NEWPLUS/TDA_DATA/Data/ folder instead of zip file
|
|
||||||
cocos2d::CCFileUtils::setResource("HelloWorld.zip");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // CC_PLATFORM_WOPHONE
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_AIRPLAY)
|
|
||||||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
|
||||||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
||||||
#endif
|
|
||||||
bRet = true;
|
|
||||||
} while (0);
|
|
||||||
return bRet;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool AppDelegate::applicationDidFinishLaunching()
|
|
||||||
{
|
|
||||||
// initialize director
|
|
||||||
CCDirector *pDirector = CCDirector::sharedDirector();
|
|
||||||
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
|
|
||||||
|
|
||||||
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
|
|
||||||
// pDirector->enableRetinaDisplay(true);
|
|
||||||
|
|
||||||
// turn on display FPS
|
|
||||||
pDirector->setDisplayFPS(true);
|
|
||||||
|
|
||||||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
|
||||||
|
|
||||||
// set FPS. the default value is 1.0/60 if you don't call this
|
|
||||||
pDirector->setAnimationInterval(1.0 / 60);
|
|
||||||
|
|
||||||
// init lua engine
|
|
||||||
CCLuaEngine* pEngine = CCLuaEngine::sharedEngine();
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
||||||
unsigned long size;
|
|
||||||
char *pFileContent = (char*)CCFileUtils::getFileData("hello.lua", "r", &size);
|
|
||||||
|
|
||||||
if (pFileContent)
|
|
||||||
{
|
|
||||||
// copy the file contents and add '\0' at the end, or the lua parser can not parse it
|
|
||||||
char *pCodes = new char[size + 1];
|
|
||||||
pCodes[size] = '\0';
|
|
||||||
memcpy(pCodes, pFileContent, size);
|
|
||||||
delete[] pFileContent;
|
|
||||||
|
|
||||||
pEngine->executeString(pCodes);
|
|
||||||
delete []pCodes;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) || (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
|
||||||
string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
|
|
||||||
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
|
|
||||||
pEngine->executeScriptFile(path.c_str());
|
|
||||||
#endif
|
|
||||||
|
|
||||||
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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->pause();
|
|
||||||
|
|
||||||
// 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()
|
|
||||||
{
|
|
||||||
CCDirector::sharedDirector()->resume();
|
|
||||||
|
|
||||||
// if you use SimpleAudioEngine, it must resume here
|
|
||||||
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
|
|
||||||
}
|
|
|
@ -1,43 +0,0 @@
|
||||||
#ifndef _APP_DELEGATE_H_
|
|
||||||
#define _APP_DELEGATE_H_
|
|
||||||
|
|
||||||
#include "CCApplication.h"
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief The cocos2d Application.
|
|
||||||
|
|
||||||
The reason for implement as private inheritance is to hide some interface call by CCDirector.
|
|
||||||
*/
|
|
||||||
class AppDelegate : private cocos2d::CCApplication
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
AppDelegate();
|
|
||||||
virtual ~AppDelegate();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement for initialize OpenGL instance, set source path, etc...
|
|
||||||
*/
|
|
||||||
virtual bool initInstance();
|
|
||||||
|
|
||||||
/**
|
|
||||||
@brief Implement CCDirector and CCScene 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_
|
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
cocos2d-x http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Copyright (c) 2008-2010 - (see each file to see the different copyright owners)
|
|
||||||
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,10 +0,0 @@
|
||||||
License for Lua 5.0 and later versions
|
|
||||||
http://www.lua.org/license.html
|
|
||||||
|
|
||||||
Copyright © 1994Ð2011 Lua.org, PUC-Rio.
|
|
||||||
|
|
||||||
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.
|
|
|
@ -1,8 +0,0 @@
|
||||||
//
|
|
||||||
// Prefix header for all source files of the '___PROJECTNAME___' target in the '___PROJECTNAME___' project
|
|
||||||
//
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#endif
|
|
|
@ -1 +0,0 @@
|
||||||
5fe89fb5bd58cedf13b0363f97b20e3ea7ff255d
|
|
|
@ -1 +0,0 @@
|
||||||
aec1c0a8c8068377fddca5ddd32084d8c3c3c419
|
|
|
@ -1 +0,0 @@
|
||||||
d7290c34702d1c6bdb368acb060d93b42d5deff8
|
|
|
@ -1,153 +0,0 @@
|
||||||
-- create scene & layer
|
|
||||||
layerFarm = cocos2d.CCLayer:node()
|
|
||||||
layerFarm:setIsTouchEnabled(true)
|
|
||||||
|
|
||||||
layerMenu = cocos2d.CCLayer:node()
|
|
||||||
|
|
||||||
sceneGame = cocos2d.CCScene:node()
|
|
||||||
sceneGame:addChild(layerFarm)
|
|
||||||
sceneGame:addChild(layerMenu)
|
|
||||||
|
|
||||||
winSize = cocos2d.CCDirector:sharedDirector():getWinSize()
|
|
||||||
|
|
||||||
-- add in farm background
|
|
||||||
spriteFarm = cocos2d.CCSprite:spriteWithFile("farm.jpg")
|
|
||||||
spriteFarm:setPosition(cocos2d.CCPoint(winSize.width/2 + 80, winSize.height/2))
|
|
||||||
layerFarm:addChild(spriteFarm)
|
|
||||||
|
|
||||||
-- touch handers
|
|
||||||
pointBegin = nil
|
|
||||||
|
|
||||||
function btnTouchMove(e)
|
|
||||||
cocos2d.CCLuaLog("btnTouchMove")
|
|
||||||
if pointBegin ~= nil then
|
|
||||||
local v = e[1]
|
|
||||||
local pointMove = v:locationInView(v:view())
|
|
||||||
pointMove = cocos2d.CCDirector:sharedDirector():convertToGL(pointMove)
|
|
||||||
local positionCurrent = layerFarm:getPosition()
|
|
||||||
layerFarm:setPosition(cocos2d.CCPoint(positionCurrent.x + pointMove.x - pointBegin.x, positionCurrent.y + pointMove.y - pointBegin.y))
|
|
||||||
pointBegin = pointMove
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function btnTouchBegin(e)
|
|
||||||
cocos2d.CCLuaLog("btnTouchBegin")
|
|
||||||
for k,v in ipairs(e) do
|
|
||||||
pointBegin = v:locationInView(v:view())
|
|
||||||
pointBegin = cocos2d.CCDirector:sharedDirector():convertToGL(pointBegin)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function btnTouchEnd(e)
|
|
||||||
cocos2d.CCLuaLog("btnTouchEnd")
|
|
||||||
touchStart = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
-- regiester touch handlers
|
|
||||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHBEGAN, "btnTouchBegin")
|
|
||||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHMOVED, "btnTouchMove")
|
|
||||||
layerFarm.__CCTouchDelegate__:registerScriptTouchHandler(cocos2d.CCTOUCHENDED, "btnTouchEnd")
|
|
||||||
|
|
||||||
|
|
||||||
-- add land sprite
|
|
||||||
for i=0,3,1 do
|
|
||||||
for j=0,1,1 do
|
|
||||||
spriteLand = cocos2d.CCSprite:spriteWithFile("land.png")
|
|
||||||
layerFarm:addChild(spriteLand)
|
|
||||||
spriteLand:setPosition(cocos2d.CCPoint(200+j*180 - i%2*90, 10+i*95/2))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add crop
|
|
||||||
|
|
||||||
for i=0,3,1 do
|
|
||||||
for j=0,1,1 do
|
|
||||||
|
|
||||||
textureCrop = cocos2d.CCTextureCache:sharedTextureCache():addImage("crop.png")
|
|
||||||
frameCrop = cocos2d.CCSpriteFrame:frameWithTexture(textureCrop, cocos2d.CCRectMake(0, 0, 105, 95))
|
|
||||||
spriteCrop = cocos2d.CCSprite:spriteWithSpriteFrame(frameCrop);
|
|
||||||
|
|
||||||
layerFarm:addChild(spriteCrop)
|
|
||||||
|
|
||||||
spriteCrop:setPosition(cocos2d.CCPoint(10+200+j*180 - i%2*90, 30+10+i*95/2))
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- add the moving dog
|
|
||||||
|
|
||||||
FrameWidth = 105
|
|
||||||
FrameHeight = 95
|
|
||||||
|
|
||||||
textureDog = cocos2d.CCTextureCache:sharedTextureCache():addImage("dog.png")
|
|
||||||
frame0 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(0, 0, FrameWidth, FrameHeight))
|
|
||||||
frame1 = cocos2d.CCSpriteFrame:frameWithTexture(textureDog, cocos2d.CCRectMake(FrameWidth*1, 0, FrameWidth, FrameHeight))
|
|
||||||
|
|
||||||
spriteDog = cocos2d.CCSprite:spriteWithSpriteFrame(frame0)
|
|
||||||
spriteDog:setPosition(cocos2d.CCPoint(0, winSize.height/4*3))
|
|
||||||
layerFarm:addChild(spriteDog)
|
|
||||||
|
|
||||||
animFrames = cocos2d.CCMutableArray_CCSpriteFrame__:new(2)
|
|
||||||
animFrames:addObject(frame0)
|
|
||||||
animFrames:addObject(frame1)
|
|
||||||
|
|
||||||
animation = cocos2d.CCAnimation:animationWithFrames(animFrames, 0.5)
|
|
||||||
|
|
||||||
animate = cocos2d.CCAnimate:actionWithAnimation(animation, false);
|
|
||||||
spriteDog:runAction(cocos2d.CCRepeatForever:actionWithAction(animate))
|
|
||||||
|
|
||||||
|
|
||||||
-- add a popup menu
|
|
||||||
|
|
||||||
function menuCallbackClosePopup()
|
|
||||||
-- stop test sound effect
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():stopEffect(effectID)
|
|
||||||
menuPopup:setIsVisible(false)
|
|
||||||
end
|
|
||||||
|
|
||||||
menuPopupItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
|
||||||
menuPopupItem:setPosition( cocos2d.CCPoint(0, 0) )
|
|
||||||
menuPopupItem:registerScriptHandler("menuCallbackClosePopup")
|
|
||||||
menuPopup = cocos2d.CCMenu:menuWithItem(menuPopupItem)
|
|
||||||
menuPopup:setPosition( cocos2d.CCPoint(winSize.width/2, winSize.height/2) )
|
|
||||||
menuPopup:setIsVisible(false)
|
|
||||||
layerMenu:addChild(menuPopup)
|
|
||||||
|
|
||||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
|
||||||
|
|
||||||
function menuCallbackOpenPopup()
|
|
||||||
-- loop test sound effect
|
|
||||||
-- NOTE: effectID is global, so it can be used to stop
|
|
||||||
effectID = CocosDenshion.SimpleAudioEngine:sharedEngine():playEffect("effect1.wav")
|
|
||||||
menuPopup:setIsVisible(true)
|
|
||||||
end
|
|
||||||
|
|
||||||
menuToolsItem = cocos2d.CCMenuItemImage:itemFromNormalImage("menu1.png","menu1.png")
|
|
||||||
menuToolsItem:setPosition( cocos2d.CCPoint(0, 0) )
|
|
||||||
menuToolsItem:registerScriptHandler("menuCallbackOpenPopup")
|
|
||||||
menuTools = cocos2d.CCMenu:menuWithItem(menuToolsItem)
|
|
||||||
menuTools:setPosition( cocos2d.CCPoint(30, 40) )
|
|
||||||
layerMenu:addChild(menuTools)
|
|
||||||
|
|
||||||
|
|
||||||
function tick()
|
|
||||||
|
|
||||||
point = spriteDog:getPosition();
|
|
||||||
|
|
||||||
if point.x > winSize.width then
|
|
||||||
point.x = 0
|
|
||||||
spriteDog:setPosition(point)
|
|
||||||
else
|
|
||||||
point.x = point.x + 1
|
|
||||||
spriteDog:setPosition(point)
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
|
|
||||||
cocos2d.CCScheduler:sharedScheduler():scheduleScriptFunc("tick", 0.01, false)
|
|
||||||
|
|
||||||
-- run
|
|
||||||
-- play background music
|
|
||||||
CocosDenshion.SimpleAudioEngine:sharedEngine():playBackgroundMusic("background.mp3", true);
|
|
||||||
|
|
||||||
cocos2d.CCDirector:sharedDirector():runWithScene(sceneGame)
|
|
Binary file not shown.
|
@ -1 +0,0 @@
|
||||||
23cd0723f3707e7fc8c77d718bf3fc0b81b105f6
|
|
|
@ -1,17 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
@class RootViewController;
|
|
||||||
|
|
||||||
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
|
|
||||||
UIWindow *window;
|
|
||||||
RootViewController *viewController;
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,110 +0,0 @@
|
||||||
//
|
|
||||||
// AppController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
#import "AppController.h"
|
|
||||||
#import "cocos2d.h"
|
|
||||||
#import "EAGLView.h"
|
|
||||||
#import "AppDelegate.h"
|
|
||||||
|
|
||||||
#import "RootViewController.h"
|
|
||||||
|
|
||||||
@implementation AppController
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Application lifecycle
|
|
||||||
|
|
||||||
// cocos2d application instance
|
|
||||||
static AppDelegate s_sharedApplication;
|
|
||||||
|
|
||||||
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
||||||
|
|
||||||
// Override point for customization after application launch.
|
|
||||||
|
|
||||||
// Add the view controller's view to the window and display.
|
|
||||||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
|
||||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
|
||||||
pixelFormat: kEAGLColorFormatRGBA8
|
|
||||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
|
||||||
preserveBackbuffer: NO
|
|
||||||
sharegroup: nil
|
|
||||||
multiSampling: NO
|
|
||||||
numberOfSamples: 0 ];
|
|
||||||
|
|
||||||
// Use RootViewController manage EAGLView
|
|
||||||
viewController = [[RootViewController alloc] initWithNibName:nil bundle:nil];
|
|
||||||
viewController.wantsFullScreenLayout = YES;
|
|
||||||
viewController.view = __glView;
|
|
||||||
|
|
||||||
// Set RootViewController to window
|
|
||||||
[window addSubview: viewController.view];
|
|
||||||
[window makeKeyAndVisible];
|
|
||||||
|
|
||||||
[[UIApplication sharedApplication] setStatusBarHidden: YES];
|
|
||||||
|
|
||||||
cocos2d::CCApplication::sharedApplication().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::CCDirector::sharedDirector()->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::CCDirector::sharedDirector()->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::CCApplication::sharedApplication().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::CCApplication::sharedApplication().applicationWillEnterForeground();
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Called when the application is about to terminate.
|
|
||||||
See also applicationDidEnterBackground:.
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Memory management
|
|
||||||
|
|
||||||
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
|
|
||||||
/*
|
|
||||||
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
|
|
||||||
*/
|
|
||||||
cocos2d::CCDirector::sharedDirector()->purgeCachedData();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
- (void)dealloc {
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.h
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
|
|
||||||
@interface RootViewController : UIViewController {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,61 +0,0 @@
|
||||||
//
|
|
||||||
// RootViewController.mm
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#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.
|
|
||||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
||||||
return UIInterfaceOrientationIsLandscape( interfaceOrientation );
|
|
||||||
}
|
|
||||||
|
|
||||||
- (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
|
|
|
@ -1,16 +0,0 @@
|
||||||
//
|
|
||||||
// main.m
|
|
||||||
// ___PROJECTNAME___
|
|
||||||
//
|
|
||||||
// Created by ___FULLUSERNAME___ on ___DATE___.
|
|
||||||
// Copyright ___ORGANIZATIONNAME___ ___YEAR___. All rights reserved.
|
|
||||||
//
|
|
||||||
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
|
||||||
NSAutoreleasePool *pool = [NSAutoreleasePool new];
|
|
||||||
int retVal = UIApplicationMain(argc, argv, nil, @"AppController");
|
|
||||||
[pool release];
|
|
||||||
return retVal;
|
|
||||||
}
|
|
Loading…
Reference in New Issue