mirror of https://github.com/axmolengine/axmol.git
Merge branch 'gles20' of https://github.com/cocos2d/cocos2d-x into iss1201_android_build
This commit is contained in:
commit
c048fe77c6
|
@ -23,6 +23,7 @@ Thumbs.db
|
|||
[Bb]in
|
||||
[Dd]ebug*/
|
||||
*.sbr
|
||||
*.sdf
|
||||
obj/
|
||||
[Rr]elease*/
|
||||
_ReSharper*/
|
||||
|
|
|
@ -54,11 +54,6 @@ void SimpleAudioEngine::end()
|
|||
endJNI();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
preloadBackgroundMusicJNI(pszFilePath);
|
||||
|
|
|
@ -295,11 +295,6 @@ void SimpleAudioEngine::end()
|
|||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
openMediaPlayer(s_pBackPlayer, pszFilePath);
|
||||
|
|
|
@ -52,12 +52,6 @@ public:
|
|||
*/
|
||||
static void end();
|
||||
|
||||
/**
|
||||
@brief Set the zip file name
|
||||
@param pszZipFileName The relative path of the .zip file
|
||||
*/
|
||||
static void setResource(const char* pszZipFileName);
|
||||
|
||||
/**
|
||||
@brief Preload background music
|
||||
@param pszFilePath The path of the background music file,or the FileName of T_SoundResInfo
|
||||
|
|
|
@ -172,11 +172,6 @@ void SimpleAudioEngine::end()
|
|||
static_end();
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
static_preloadBackgroundMusic(pszFilePath);
|
||||
|
|
|
@ -33,9 +33,6 @@ void SimpleAudioEngine::end() {
|
|||
// return;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName) {
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BackgroundMusic
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -95,11 +95,6 @@ namespace CocosDenshion
|
|||
}
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::preloadBackgroundMusic(const char* pszFilePath)
|
||||
{
|
||||
s3eFile *fileHandle = s3eFileOpen(pszFilePath, "rb");
|
||||
|
|
|
@ -158,10 +158,6 @@ namespace CocosDenshion
|
|||
stopBackground(true);
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
}
|
||||
|
||||
//
|
||||
// OGG support
|
||||
//
|
||||
|
|
|
@ -62,10 +62,6 @@ void SimpleAudioEngine::end()
|
|||
return;
|
||||
}
|
||||
|
||||
void SimpleAudioEngine::setResource(const char* pszZipFileName)
|
||||
{
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BackgroundMusic
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -21,21 +22,23 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
|||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
{
|
||||
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
||||
if (!CCDirector::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
|
||||
CCEGLView *view = &CCEGLView::sharedOpenGLView();
|
||||
view->setFrameSize(w, h);
|
||||
// if you want to run in WVGA with HVGA resource, set it
|
||||
// view->create(480, 320);
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
CCApplication::sharedApplication().run();
|
||||
}
|
||||
else
|
||||
{
|
||||
cocos2d::CCTextureCache::reloadAllTextures();
|
||||
cocos2d::CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
|
||||
CCTextureCache::reloadAllTextures();
|
||||
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
9b310a8b553efc1db798797273bd0bfb1b11c857
|
||||
3ffb5ef04b897f971e1e9c941002d06e5a91da50
|
|
@ -11,6 +11,7 @@
|
|||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -24,16 +25,16 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
|||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
{
|
||||
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
||||
if (!CCDirector::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
|
||||
CCEGLView *view = &CCEGLView::sharedOpenGLView();
|
||||
view->setFrameSize(w, h);
|
||||
// if you want to run in WVGA with HVGA resource, set it
|
||||
// view->setDesignResolutionSize(480, 320); Please change it to (320, 480) if you're in portrait mode.
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
CCApplication::sharedApplication().run();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -41,9 +42,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
ccGLInvalidateStateCache();
|
||||
|
||||
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
|
||||
cocos2d::CCTextureCache::reloadAllTextures();
|
||||
cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
cocos2d::CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
CCTextureCache::reloadAllTextures();
|
||||
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
918b8b44c7b180874afc0599a0e1b2b4e13f1e2a
|
||||
92dc1f3cb8db6691dae94a502b38db89e5293d2d
|
|
@ -41,7 +41,7 @@
|
|||
<Tool
|
||||
Name="VCCLCompilerTool"
|
||||
Optimization="0"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)cocos2dx1";"$(SolutionDir)cocos2dx\actions";"$(SolutionDir)cocos2dx\base_nodes";"$(SolutionDir)cocos2dx\cocoa";"$(SolutionDir)cocos2dx\effects";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)cocos2dx\kazmath\include";"$(SolutionDir)cocos2dx\keypad_dispatcher";"$(SolutionDir)cocos2dx\label_nodes";"$(SolutionDir)cocos2dx\layers_scenes_transitions_nodes";"$(SolutionDir)cocos2dx\menu_nodes";"$(SolutionDir)cocos2dx\misc_nodes";"$(SolutionDir)cocos2dx\particle_nodes";"$(SolutionDir)cocos2dx\script_support";"$(SolutionDir)cocos2dx\shaders";"$(SolutionDir)cocos2dx\sprite_nodes";"$(SolutionDir)cocos2dx\support";"$(SolutionDir)cocos2dx\text_input_node";"$(SolutionDir)cocos2dx\textures";"$(SolutionDir)cocos2dx\tileMap_parallax_nodes";"$(SolutionDir)cocos2dx\touch_dispatcher";"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx\platform\win32";"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\Classes"
|
||||
AdditionalIncludeDirectories=""$(SolutionDir)cocos2dx";"$(SolutionDir)cocos2dx\actions";"$(SolutionDir)cocos2dx\base_nodes";"$(SolutionDir)cocos2dx\cocoa";"$(SolutionDir)cocos2dx\effects";"$(SolutionDir)cocos2dx\include";"$(SolutionDir)cocos2dx\kazmath\include";"$(SolutionDir)cocos2dx\keypad_dispatcher";"$(SolutionDir)cocos2dx\label_nodes";"$(SolutionDir)cocos2dx\layers_scenes_transitions_nodes";"$(SolutionDir)cocos2dx\menu_nodes";"$(SolutionDir)cocos2dx\misc_nodes";"$(SolutionDir)cocos2dx\particle_nodes";"$(SolutionDir)cocos2dx\script_support";"$(SolutionDir)cocos2dx\shaders";"$(SolutionDir)cocos2dx\sprite_nodes";"$(SolutionDir)cocos2dx\support";"$(SolutionDir)cocos2dx\text_input_node";"$(SolutionDir)cocos2dx\textures";"$(SolutionDir)cocos2dx\tileMap_parallax_nodes";"$(SolutionDir)cocos2dx\touch_dispatcher";"$(SolutionDir)cocos2dx\platform";"$(SolutionDir)cocos2dx\platform\win32";"$(SolutionDir)cocos2dx\platform\third_party\win32\OGLES";..\Classes"
|
||||
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
|
||||
MinimalRebuild="true"
|
||||
BasicRuntimeChecks="3"
|
||||
|
|
|
@ -1,76 +0,0 @@
|
|||
#!/bin/sh
|
||||
#p=$(dirname $_)
|
||||
#echo "$p"
|
||||
|
||||
#path=$(dirname $0)
|
||||
#path=${path/\./$(pwd)}
|
||||
#echo $path
|
||||
p=.
|
||||
|
||||
if [ ! -d "lib" ]; then
|
||||
mkdir "lib"
|
||||
fi
|
||||
|
||||
if [ ! -d "lib/linux" ]; then
|
||||
mkdir "lib/linux"
|
||||
fi
|
||||
|
||||
if [ ! -d "lib/linux/Debug" ]; then
|
||||
mkdir "lib/linux/Debug"
|
||||
fi
|
||||
|
||||
if [ ! -d "lib/linux/Release" ]; then
|
||||
mkdir "lib/linux/Release"
|
||||
fi
|
||||
|
||||
# copy cocosdenshino depended libs into lib/linux/Debug/
|
||||
cp CocosDenshion/third_party/linux/fmod/api/lib/*.so lib/linux/Debug
|
||||
|
||||
if [ $# -ne 0 ]; then
|
||||
if [ $1 = "clean" ]; then
|
||||
cd $p/cocos2dx/proj.linux
|
||||
make clean
|
||||
|
||||
cd ../../
|
||||
cd $p/CocosDenshion/proj.linux
|
||||
make clean
|
||||
|
||||
cd ../..
|
||||
cd $p/Box2D/proj.linux
|
||||
make clean
|
||||
|
||||
cd ../..
|
||||
cd $p/chipmunk/proj.linux
|
||||
make clean
|
||||
|
||||
cd ../../
|
||||
rm -r lib/linux/Debug/*.so
|
||||
fi
|
||||
|
||||
else
|
||||
cd $p/cocos2dx/proj.linux
|
||||
echo "**********************building cocos2dx**************************"
|
||||
make
|
||||
cp -f libcocos2d.so ../../lib/linux/Debug
|
||||
|
||||
echo "**********************building cocosdenshion*********************"
|
||||
cd ../../
|
||||
cd $p/CocosDenshion/proj.linux
|
||||
make
|
||||
cp -f libcocosdenshion.so ../../lib/linux/Debug
|
||||
|
||||
echo "**********************building Box2D******************************"
|
||||
cd ../..
|
||||
cd $p/Box2D/proj.linux
|
||||
make
|
||||
cp -f libbox2d.a ../../lib/linux/Debug
|
||||
|
||||
echo "**********************building chipmunk***************************"
|
||||
cd ../..
|
||||
cd $p/chipmunk/proj.linux
|
||||
make
|
||||
cp -f libchipmunk.a ../../lib/linux/Debug
|
||||
|
||||
cd ../../
|
||||
fi
|
||||
|
|
@ -53,6 +53,9 @@ extensions/CCControlExtension/CCInvocation.cpp \
|
|||
extensions/CCControlExtension/CCMenuPassive.cpp \
|
||||
extensions/CCControlExtension/CCScale9Sprite.cpp \
|
||||
extensions/CCControlExtension/CCSpacer.cpp \
|
||||
extensions/CCListView/CCListView.cpp \
|
||||
extensions/CCListView/CCListViewCell.cpp \
|
||||
extensions/CCTextureWatcher/CCTextureWatcher.cpp \
|
||||
kazmath/src/aabb.c \
|
||||
kazmath/src/mat3.c \
|
||||
kazmath/src/mat4.c \
|
||||
|
|
|
@ -36,7 +36,7 @@ THE SOFTWARE.
|
|||
#include "CCTransition.h"
|
||||
#include "CCSpriteFrameCache.h"
|
||||
#include "CCAutoreleasePool.h"
|
||||
#include "platform/platform.h"
|
||||
#include "platform.h"
|
||||
#include "CCApplication.h"
|
||||
#include "CCLabelBMFont.h"
|
||||
#include "CCActionManager.h"
|
||||
|
@ -47,17 +47,17 @@ THE SOFTWARE.
|
|||
#include "CCAnimationCache.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCUserDefault.h"
|
||||
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
|
||||
#include "ccGLStateCache.h"
|
||||
#include "CCShaderCache.h"
|
||||
#include "kazmath/kazmath.h"
|
||||
#include "kazmath/GL/matrix.h"
|
||||
#include "support/CCProfiling.h"
|
||||
#include "CCEGLView.h"
|
||||
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
|
||||
#include "extensions/CCTextureWatcher/CCTextureWatcher.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
using namespace cocos2d;
|
||||
|
||||
unsigned int g_uNumberOfDraws = 0;
|
||||
|
||||
|
@ -131,6 +131,9 @@ bool CCDirector::init(void)
|
|||
m_fContentScaleFactor = 1;
|
||||
m_bIsContentScaleSupported = false;
|
||||
|
||||
m_pWatcherFun = NULL;
|
||||
m_pWatcherSender = NULL;
|
||||
|
||||
// scheduler
|
||||
m_pScheduler = new CCScheduler();
|
||||
// action manager
|
||||
|
@ -232,6 +235,10 @@ void CCDirector::drawScene(void)
|
|||
showStats();
|
||||
}
|
||||
|
||||
if (m_pWatcherFun && m_pWatcherSender)
|
||||
{
|
||||
(*m_pWatcherFun)(m_pWatcherSender);
|
||||
}
|
||||
|
||||
kmGLPopMatrix();
|
||||
|
||||
|
@ -584,7 +591,8 @@ void CCDirector::purgeDirector()
|
|||
|
||||
// cocos2d-x specific data structures
|
||||
CCUserDefault::purgeSharedUserDefault();
|
||||
CCNotificationCenter::purgeNotificationCenter();
|
||||
extension::CCNotificationCenter::purgeNotificationCenter();
|
||||
extension::CCTextureWatcher::purgeTextureWatcher();
|
||||
|
||||
ccGLInvalidateStateCache();
|
||||
|
||||
|
@ -933,5 +941,12 @@ void CCDisplayLinkDirector::setAnimationInterval(double dValue)
|
|||
}
|
||||
}
|
||||
|
||||
void CCDirector::setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun)
|
||||
{
|
||||
m_pWatcherFun = fun;
|
||||
m_pWatcherSender = pSender;
|
||||
}
|
||||
|
||||
|
||||
NS_CC_END
|
||||
|
||||
|
|
|
@ -273,6 +273,9 @@ public:
|
|||
void setContentScaleFactor(CCFloat scaleFactor);
|
||||
CCFloat getContentScaleFactor(void);
|
||||
|
||||
typedef void(*WatcherCallbackFun)(void *pSender);
|
||||
void setWatcherCallbackFun(void *pSender, WatcherCallbackFun fun);
|
||||
|
||||
public:
|
||||
/** CCScheduler associated with this director
|
||||
@since v2.0
|
||||
|
@ -388,6 +391,10 @@ protected:
|
|||
|
||||
/* contentScaleFactor could be simulated */
|
||||
bool m_bIsContentScaleSupported;
|
||||
|
||||
WatcherCallbackFun m_pWatcherFun;
|
||||
void *m_pWatcherSender;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -524,7 +524,10 @@ void CCNode::addChild(CCNode *child)
|
|||
|
||||
void CCNode::removeFromParentAndCleanup(bool cleanup)
|
||||
{
|
||||
this->m_pParent->removeChild(this,cleanup);
|
||||
if (m_pParent != NULL)
|
||||
{
|
||||
m_pParent->removeChild(this,cleanup);
|
||||
}
|
||||
}
|
||||
|
||||
/* "remove" logic MUST only be on this method
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
#include "CCMenu.h"
|
||||
#include "CCTouch.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCControl::CCControl()
|
||||
{
|
||||
|
@ -299,4 +299,4 @@ CCArray* CCControl::dispatchListforControlEvent(CCControlEvent controlEvent)
|
|||
return invocationList;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "CCControlUtils.h"
|
||||
#include "CCLayer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCInvocation;
|
||||
|
||||
|
@ -206,6 +206,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -33,7 +33,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -462,4 +462,4 @@ void CCControlButton::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
|||
sendActionsForControlEvents(CCControlEventTouchCancel);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include "CCInvocation.h"
|
||||
#include "CCScale9Sprite.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
/** @class CCControlButton Button control for Cocos2D. */
|
||||
class CC_DLL CCControlButton : public CCControl
|
||||
|
@ -181,6 +181,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -33,7 +33,7 @@
|
|||
#include "CCSpriteFrameCache.h"
|
||||
#include "CCSpriteBatchNode.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
bool CCControlColourPicker::init()
|
||||
{
|
||||
|
@ -158,4 +158,4 @@ bool CCControlColourPicker::ccTouchBegan(CCTouch* touch, CCEvent* pEvent)
|
|||
return false;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#include "CCControlHuePicker.h"
|
||||
#include "CCControlSaturationBrightnessPicker.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCControlColourPicker: public CCControl
|
||||
{
|
||||
|
@ -65,6 +65,6 @@ protected:
|
|||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -31,7 +31,7 @@
|
|||
#include "CCControlHuePicker.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCControlHuePicker::~CCControlHuePicker()
|
||||
{
|
||||
|
@ -158,4 +158,4 @@ void CCControlHuePicker::ccTouchMoved(CCTouch* touch, CCEvent* event)
|
|||
//checkSliderPosition(touchLocation);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include "CCControl.h"
|
||||
#include "CCInvocation.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCControlHuePicker : public CCControl
|
||||
{
|
||||
|
@ -64,6 +64,6 @@ protected:
|
|||
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -31,7 +31,7 @@
|
|||
#include "CCControlSaturationBrightnessPicker.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCControlSaturationBrightnessPicker::~CCControlSaturationBrightnessPicker()
|
||||
{
|
||||
|
@ -176,4 +176,4 @@ void CCControlSaturationBrightnessPicker::ccTouchMoved(CCTouch* touch, CCEvent*
|
|||
//checkSliderPosition(touchLocation);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
#include "CCControl.h"
|
||||
#include "CCInvocation.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCControlSaturationBrightnessPicker : public CCControl
|
||||
{
|
||||
|
@ -68,6 +68,6 @@ protected:
|
|||
virtual void ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -31,7 +31,7 @@
|
|||
#include "CCTouch.h"
|
||||
#include "CCDirector.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCControlSlider::~CCControlSlider()
|
||||
{
|
||||
|
@ -218,4 +218,4 @@ float CCControlSlider::valueForLocation(CCPoint location)
|
|||
return m_minimumValue + percent * (m_maximumValue - m_minimumValue);
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
#define SLIDER_MARGIN_H 24
|
||||
#define SLIDER_MARGIN_V 8
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCControlSlider: public CCControl
|
||||
{
|
||||
|
@ -106,6 +106,6 @@ protected:
|
|||
float valueForLocation(CCPoint location);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -24,16 +24,9 @@
|
|||
*/
|
||||
|
||||
#include "CCControlSwitch.h"
|
||||
#include "CCPointExtension.h"
|
||||
#include "CCLabelTTF.h"
|
||||
#include "CCRenderTexture.h"
|
||||
#include "CCTouch.h"
|
||||
#include "CCDirector.h"
|
||||
#include "ccShaders.h"
|
||||
#include "CCActionTween.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
#include "cocos2d.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
// CCControlSwitchSprite
|
||||
|
||||
class CCControlSwitchSprite : public CCSprite, public CCActionTweenDelegate
|
||||
|
@ -438,4 +431,4 @@ void CCControlSwitch::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent)
|
|||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -29,11 +29,13 @@
|
|||
|
||||
#include "CCControl.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
namespace cocos2d { class CCSprite; }
|
||||
namespace cocos2d { class CCLabelTTF; }
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCControlSwitchSprite;
|
||||
class CCSprite;
|
||||
class CCLabelTTF;
|
||||
|
||||
/** @class CCControlSwitch Switch control for Cocos2D. */
|
||||
class CC_DLL CCControlSwitch : public CCControl
|
||||
|
@ -85,7 +87,7 @@ protected:
|
|||
};
|
||||
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif /* __CCCONTROLSWITCH_H__ */
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#include "CCControlUtils.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCSprite* CCControlUtils::addSpriteToTargetWithPosAndAnchor(const char* spriteName, CCNode * target, CCPoint pos, CCPoint anchor)
|
||||
{
|
||||
|
@ -146,4 +146,4 @@ CCRect CCControlUtils::CCRectUnion(const CCRect& src1, const CCRect& src2)
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
#include "CCSprite.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
typedef struct
|
||||
{
|
||||
|
@ -60,7 +60,7 @@ public:
|
|||
CCColor3bObject(ccColor3B s_value):value(s_value){}
|
||||
};
|
||||
|
||||
class CCControlUtils
|
||||
class CC_DLL CCControlUtils
|
||||
{
|
||||
public:
|
||||
static CCSprite* addSpriteToTargetWithPosAndAnchor(const char* spriteName, CCNode * target, CCPoint pos, CCPoint anchor);
|
||||
|
@ -69,6 +69,6 @@ public:
|
|||
static CCRect CCRectUnion(const CCRect& src1, const CCRect& src2);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -1,6 +1,6 @@
|
|||
#include "CCInvocation.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCInvocation::CCInvocation(CCObject* target, SEL_MenuHandler action, CCControlEvent controlEvent)
|
||||
{
|
||||
|
@ -17,4 +17,4 @@ void CCInvocation::invoke(CCObject* sender)
|
|||
}
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "CCObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
typedef unsigned int CCControlEvent;
|
||||
|
||||
|
@ -23,6 +23,6 @@ public:
|
|||
void invoke(CCObject* sender);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
enum
|
||||
{
|
||||
|
@ -437,4 +437,4 @@ const ccColor3B& CCMenuPassive::getColor(void)
|
|||
return m_tColor;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
#include "CCControl.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCMenuPassive : public CCLayer, public CCRGBAProtocol
|
||||
{
|
||||
|
@ -59,6 +59,6 @@ public:
|
|||
virtual bool getIsOpacityModifyRGB(void) { return false;}
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -13,7 +13,7 @@
|
|||
#include "CCSprite.h"
|
||||
#include "CCPointExtension.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCScale9Sprite::CCScale9Sprite()
|
||||
{
|
||||
|
@ -461,4 +461,4 @@ bool CCScale9Sprite::getIsOpacityModifyRGB()
|
|||
return m_bIsOpacityModifyRGB;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
#include "CCProtocols.h"
|
||||
|
||||
|
||||
NS_CC_BEGIN
|
||||
namespace cocos2d { class CCSprite; }
|
||||
namespace cocos2d { class CCSpriteBatchNode; }
|
||||
namespace cocos2d { class CCSpriteFrame; }
|
||||
|
||||
class CCSprite;
|
||||
class CCSpriteBatchNode;
|
||||
class CCSpriteFrame;
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
enum positions
|
||||
{
|
||||
|
@ -276,6 +276,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CCScale9Sprite_H__
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
#include "CCSpacer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
CCSpacer* CCSpacer::verticalSpacer(float space)
|
||||
{
|
||||
|
@ -20,4 +20,4 @@ CCSpacer* CCSpacer::horizontalSpacer(float space)
|
|||
return pRet;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
#include "CCLayer.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCSpacer: public CCLayer
|
||||
{
|
||||
|
@ -12,6 +12,6 @@ public:
|
|||
static CCSpacer* horizontalSpacer(float space);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -0,0 +1,42 @@
|
|||
#ifndef __CCCONTROL_DEFINE_H__
|
||||
#define __CCCONTROL_DEFINE_H__
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
typedef enum
|
||||
{
|
||||
PARENT_CENTER,
|
||||
VERTICAL_TOP,
|
||||
VERTICAL_BOTTOM,
|
||||
HORIZONTAL_LEFT,
|
||||
HORIZONTAL_RIGHT,
|
||||
ABS_WITH_PIXEL,
|
||||
ABS_WITH_PERCENT,
|
||||
REF_PREV_X_INC,
|
||||
REF_PREV_X_DEC,
|
||||
REF_PREV_Y_INC,
|
||||
REF_PREV_Y_DEC,
|
||||
REL_FLOW
|
||||
} LAYOUT_TYPE;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LAYOUT_TYPE t;
|
||||
union
|
||||
{
|
||||
float pixel_val;
|
||||
float percent_val;
|
||||
} val;
|
||||
} LayoutParamVal;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
LayoutParamVal val_x;
|
||||
LayoutParamVal val_y;
|
||||
float padding;
|
||||
bool wrap;
|
||||
} LayoutParam;
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif /* __CCCONTROL_DEFINE_H__ */
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,188 @@
|
|||
#ifndef __CC_LIST_VIEW_H__
|
||||
#define __CC_LIST_VIEW_H__
|
||||
|
||||
#include <time.h>
|
||||
#include "platform.h"
|
||||
#include <vector>
|
||||
#include <string>
|
||||
//#include "../lua/cocos2dx_support/CCLuaEngine.h"
|
||||
#include "CCListViewCell.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCRange
|
||||
{
|
||||
public:
|
||||
CCRange()
|
||||
{
|
||||
this->location = 0;
|
||||
this->length = 0;
|
||||
}
|
||||
|
||||
CCRange(unsigned int loc, unsigned int len)
|
||||
{
|
||||
this->location = loc;
|
||||
this->length = len;
|
||||
}
|
||||
|
||||
static unsigned int CCMaxRange(CCRange range)
|
||||
{
|
||||
return (range.location + range.length-1);
|
||||
}
|
||||
|
||||
static bool CCLocationInRange(unsigned int loc, CCRange range)
|
||||
{
|
||||
return (loc - range.location <= range.length);
|
||||
}
|
||||
|
||||
static bool CCEqualRanges(CCRange range1, CCRange range2)
{
return (range1.location == range2.location && range1.length == range2.length);
}
|
||||
|
||||
unsigned int length;
|
||||
unsigned int location;
|
||||
};
|
||||
|
||||
#define CCRangeMake(__min__, __max__) CCRange((__min__), (__max__))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CCListViewSlideDirNone,
|
||||
CCListViewSlideDirUp,
|
||||
CCListViewSlideDirDown,
|
||||
CCListViewSlideDirLeft,
|
||||
CCListViewSlideDirRight,
|
||||
} CCListViewSlideDir;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CCListViewStateWatting,
|
||||
CCListViewStateTrackingTouch,
|
||||
CCListViewStateEaseOut,
|
||||
CCListViewStateFix,
|
||||
CCListViewStateScroll,
|
||||
} CCListViewState;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
CCListViewModeHorizontal,
|
||||
CCListViewModeVertical,
|
||||
} CCListViewMode;
|
||||
|
||||
typedef struct _CCListViewProtrolData
|
||||
{
|
||||
unsigned int nNumberOfRows;
|
||||
unsigned int nRow;
|
||||
CCListViewCell *cell;
|
||||
} CCListViewProtrolData;
|
||||
|
||||
class CC_DLL CCListViewDelegate
|
||||
{
|
||||
public :
|
||||
CCListViewDelegate(){};
|
||||
virtual ~CCListViewDelegate(){};
|
||||
|
||||
virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)=0;
|
||||
virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)=0;
|
||||
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)=0;
|
||||
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)=0;
|
||||
};
|
||||
|
||||
|
||||
class CC_DLL CCListView : public CCLayerColor
|
||||
{
|
||||
public:
|
||||
virtual ~CCListView(void);
|
||||
CCListView(void);
|
||||
|
||||
static CCListView* viewWithMode(CCListViewMode mode);
|
||||
bool initWithMode(CCListViewMode mode);
|
||||
|
||||
void setDelegateName(const char* pszName);
|
||||
void selectCellAtRow(unsigned int nRow);
|
||||
void unselectCellAtRow(unsigned int nRow);
|
||||
void scrollCellToFront(unsigned int nRow, bool bAnimated);
|
||||
void scrollCellToBack(unsigned int nRow, bool bAnimated);
|
||||
void reload(void);
|
||||
void insertCellsAtRow(unsigned int nRow, unsigned int nCount);
|
||||
void deleteCellsAtRow(unsigned int nRow, unsigned int nCount);
|
||||
CCListViewCell *cellAtRow(unsigned int nRow);
|
||||
|
||||
CCListViewSlideDir getSlideDir(CCPoint ptTouchBegan, CCPoint ptTouchEnd);
|
||||
inline CCListViewSlideDir getSlideDir(void) { return m_nSlideDir; }
|
||||
|
||||
inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; }
|
||||
inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; }
|
||||
inline CCListViewMode getMode(void) { return m_nMode; }
|
||||
|
||||
inline void setListViewParent(CCListView *pParent) { m_pListViewParent = pParent; }
|
||||
inline CCListView *getListViewParent(void) { return m_pListViewParent; }
|
||||
|
||||
inline void setIsEnabled(bool bEnabled) { m_bIsEnabled = bEnabled; }
|
||||
inline bool getIsEnabled(void) { return m_bIsEnabled; }
|
||||
|
||||
// un
|
||||
void setDelegate(const CCListViewDelegate *pDelegate) { m_pDelegate = const_cast<CCListViewDelegate*>(pDelegate);}
|
||||
void finishFix(void);
|
||||
void finishScroll(void);
|
||||
void finishEaseOut(void);
|
||||
|
||||
public:
|
||||
virtual bool ccTouchBegan(CCTouch* touch, CCEvent* event);
|
||||
virtual void ccTouchEnded(CCTouch* touch, CCEvent* event);
|
||||
virtual void ccTouchCancelled(CCTouch *touch, CCEvent* event);
|
||||
virtual void ccTouchMoved(CCTouch* touch, CCEvent* event);
|
||||
|
||||
virtual void onEnter(void);
|
||||
virtual void onExit(void);
|
||||
|
||||
virtual void registerWithTouchDispatcher(void);
|
||||
virtual void visit(void);
|
||||
|
||||
protected:
|
||||
void displayVisibleRows(void);
|
||||
CCListViewCell* appendRowToBack(unsigned int nRow);
|
||||
CCListViewCell* appendRowToFront(unsigned int nRow);
|
||||
void fixFirstRow(void);
|
||||
void fixLastRow(void);
|
||||
void easeOutWithDistance(float dis);
|
||||
void clearUnvisibleRows(void);
|
||||
|
||||
int rowForTouch(cocos2d::CCTouch *touch);
|
||||
bool isTouchInside(CCTouch *touch);
|
||||
bool isFullFill(void);
|
||||
|
||||
void stopActionImmediately(void);
|
||||
|
||||
unsigned int triggerNumberOfCells(void);
|
||||
CCListViewCell *triggerCellForRow(unsigned int nRow);
|
||||
void triggerDidClickCellAtRow(unsigned int nRow);
|
||||
void triggerDidScrollToRow(unsigned int nRow);
|
||||
bool isMenuTouch(CCTouch *touch, CCNode *parent);
|
||||
|
||||
private:
|
||||
CCListViewState m_nState;
|
||||
CCListViewMode m_nMode;
|
||||
CCListViewSlideDir m_nSlideDir;
|
||||
CCListViewCellSeparatorStyle m_nSeparatorStyle;
|
||||
unsigned int m_nNumberOfRows;
|
||||
float m_fActionDuration;
|
||||
clock_t m_timeTouchBegan;
|
||||
CCRange m_drawedRows; //所有已绘制的cell
|
||||
CCRange m_visibleRows; //所有可见的cell
|
||||
CCPoint m_ptTouchBegan;
|
||||
CCPoint m_ptTouchEnd;
|
||||
CCPoint m_ptPanelOffset;
|
||||
CCPoint m_ptDestination;
|
||||
std::string m_strDeletegate;
|
||||
CCListViewDelegate* m_pDelegate;
|
||||
CCLayer* m_layerPanel;
|
||||
CCListView* m_pListViewParent;
|
||||
int m_nSelectedRow;
|
||||
int m_nCurrentRow;
|
||||
bool m_bIsEnabled;
|
||||
bool m_bIsOnTouch;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
|
||||
#endif // __CC_LIST_VIEW_H__
|
|
@ -0,0 +1,96 @@
|
|||
#include "CCListView.h"
|
||||
#include "CCListViewCell.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
const int TOUCHBEGIN = 1;
|
||||
const int TOUCHEND = 2;
|
||||
const int TOUCHMOVING = 3;
|
||||
const int TOUCHCANCELLED= 4;
|
||||
|
||||
|
||||
/******************************************
|
||||
**************Public Functions*************
|
||||
*******************************************/
|
||||
CCListViewCell::CCListViewCell(void)
|
||||
:m_nSeparatorStyle(CCListViewCellSeparatorStyleNone)
|
||||
,m_bIsSelected(false)
|
||||
{
|
||||
setIsTouchEnabled(true);
|
||||
m_selectionColor = ccc4(0, 0, 255, 255);
|
||||
m_separatorLineColor = ccc3(128, 128, 128);
|
||||
}
|
||||
|
||||
CCListViewCell::~CCListViewCell(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CCListViewCell *CCListViewCell::node(void)
|
||||
{
|
||||
CCListViewCell *pRet = new CCListViewCell();
|
||||
pRet->initWithColorWidthHeight(ccc4(255, 255, 255, 255), 0, 0);
|
||||
pRet->autorelease();
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void CCListViewCell::selected(void)
|
||||
{
|
||||
m_bIsSelected = true;
|
||||
CCLayerColor::setColor(ccc3(m_selectionColor.r, m_selectionColor.g, m_selectionColor.b));
|
||||
CCLayerColor::setOpacity(m_selectionColor.a);
|
||||
}
|
||||
|
||||
void CCListViewCell::unselected(void)
|
||||
{
|
||||
m_bIsSelected = false;
|
||||
CCLayerColor::setColor(ccc3(m_normalColor.r, m_normalColor.g, m_normalColor.b));
|
||||
CCLayerColor::setOpacity(m_normalColor.a);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
**************Virturl Functions************
|
||||
*******************************************/
|
||||
bool CCListViewCell::initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height)
|
||||
{
|
||||
this->m_normalColor = color;
|
||||
return CCLayerColor::initWithColor(color, width, height);
|
||||
}
|
||||
|
||||
void CCListViewCell::draw(void)
|
||||
{
|
||||
CCLayerColor::draw();
|
||||
CCSize size = this->getContentSize();
|
||||
CCListView *owner = this->getOwner();
|
||||
if (CCListViewCellSeparatorStyleSingleLine == m_nSeparatorStyle)
|
||||
{
|
||||
glLineWidth(1.0f);
|
||||
ccDrawColor4B(m_separatorLineColor.r, m_separatorLineColor.g, m_separatorLineColor.b, 255);
|
||||
|
||||
if (CCListViewModeHorizontal == owner->getMode())
|
||||
{
|
||||
ccDrawLine(CCPointMake(size.width, 0), CCPointMake(size.width, size.height));
|
||||
}
|
||||
else if (CCListViewModeVertical == owner->getMode())
|
||||
{
|
||||
ccDrawLine(CCPointMake(0, 0), CCPointMake(size.width, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CCListViewCell::setColor(ccColor3B var)
|
||||
{
|
||||
m_normalColor.r = var.r;
|
||||
m_normalColor.g = var.g;
|
||||
m_normalColor.b = var.b;
|
||||
CCLayerColor::setColor(var);
|
||||
}
|
||||
|
||||
void CCListViewCell::setOpacity(GLubyte var)
|
||||
{
|
||||
m_normalColor.a = var;
|
||||
CCLayerColor::setOpacity(var);
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,55 @@
|
|||
#ifndef __CC_LIST_VIEW_CELL_H_
|
||||
#define __CC_LIST_VIEW_CELL_H_
|
||||
|
||||
#include "CCControlDefine.h"
|
||||
#include "CCLayer.h"
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CCListView;
|
||||
typedef enum
|
||||
{
|
||||
CCListViewCellSeparatorStyleNone,
|
||||
CCListViewCellSeparatorStyleSingleLine,
|
||||
}CCListViewCellSeparatorStyle;
|
||||
|
||||
class CC_DLL CCListViewCell : public CCLayerColor
|
||||
{
|
||||
public:
|
||||
CCListViewCell(void);
|
||||
virtual ~CCListViewCell(void);
|
||||
|
||||
static CCListViewCell *node(void);
|
||||
|
||||
void selected(void);
|
||||
void unselected(void);
|
||||
|
||||
inline CCListViewCellSeparatorStyle getSeparatorStyle(void) { return m_nSeparatorStyle; }
|
||||
inline void setSeparatorStyle(CCListViewCellSeparatorStyle style) { m_nSeparatorStyle = style; }
|
||||
|
||||
inline ccColor4B getSelectionColor(void) { return m_selectionColor; }
|
||||
inline void setSelectionColor(ccColor4B color) { m_selectionColor = color; }
|
||||
|
||||
inline ccColor3B getSeparatorLineColor(void) { return m_separatorLineColor; }
|
||||
inline void setSeparatorLineColor(ccColor3B color) { m_separatorLineColor = color; }
|
||||
|
||||
public:
|
||||
virtual bool initWithColorWidthHeight(ccColor4B color, GLfloat width, GLfloat height);
|
||||
virtual void draw(void);
|
||||
virtual void setColor(ccColor3B color);
|
||||
virtual void setOpacity(GLubyte var);
|
||||
|
||||
private:
|
||||
inline CCListView *getOwner(void) { return (CCListView*)(this->getParent()->getParent()); }
|
||||
|
||||
private:
|
||||
CCListViewCellSeparatorStyle m_nSeparatorStyle;
|
||||
bool m_bIsSelected;
|
||||
ccColor4B m_selectionColor;
|
||||
ccColor4B m_normalColor;
|
||||
ccColor3B m_separatorLineColor;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif // __CC_LIST_VIEW_CELL_H_
|
|
@ -28,7 +28,7 @@ THE SOFTWARE.
|
|||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_BEGIN
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
static CCNotificationCenter *s_sharedNotifCenter = NULL;
|
||||
|
||||
|
@ -185,4 +185,4 @@ CCObject *CCNotificationObserver::getObject()
|
|||
return m_object;
|
||||
}
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
|
|
@ -27,9 +27,10 @@ THE SOFTWARE.
|
|||
|
||||
#include "CCObject.h"
|
||||
|
||||
NS_CC_BEGIN
|
||||
|
||||
class CCArray;
|
||||
namespace cocos2d { class CCArray; }
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCNotificationCenter : public CCObject
|
||||
{
|
||||
|
@ -59,7 +60,7 @@ private:
|
|||
//
|
||||
// variables
|
||||
//
|
||||
CCArray *m_observers;
|
||||
cocos2d::CCArray *m_observers;
|
||||
};
|
||||
|
||||
class CC_DLL CCNotificationObserver : public CCObject
|
||||
|
@ -79,6 +80,6 @@ private:
|
|||
CC_PROPERTY_READONLY(CCObject *, m_object, Object);
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif//__CCNOTIFICATIONCENTER_H__
|
|
@ -0,0 +1,342 @@
|
|||
#include "CCTextureWatcher.h"
|
||||
#include "cocos2d.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
#define NUM_PER_PAGE 4
|
||||
|
||||
CCTextureWatcher::CCTextureWatcher()
|
||||
{
|
||||
m_bHide = false;
|
||||
m_nCurrnetPage = 1;
|
||||
m_nTotalPage = 0;
|
||||
m_bFresh = true;
|
||||
m_pTextures = NULL;
|
||||
m_pszString = NULL;
|
||||
m_pLayer = CCLayerColor::layerWithColor(ccc4(128, 128, 128, 128));
|
||||
m_pLayer->retain();
|
||||
|
||||
// layer
|
||||
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
||||
size.height *= 0.6;
|
||||
m_pLayer->setContentSize(size);
|
||||
|
||||
// 屏蔽点击事件的menu
|
||||
//*
|
||||
CCLabelTTF *label = CCLabelTTF::labelWithString(" ", size, CCTextAlignmentLeft, "Arial", 12);
|
||||
CCMenuItemLabel *menuItem = CCMenuItemLabel::itemWithLabel(label);
|
||||
menuItem->setAnchorPoint(CCPoint(0, 0));
|
||||
menuItem->setPosition(CCPoint(0, 0));
|
||||
|
||||
CCMenu *menu = CCMenu::menuWithItem(menuItem);
|
||||
menu->setAnchorPoint(CCPoint(0, 0));
|
||||
menu->setPosition(CCPoint(0, 0));
|
||||
m_pLayer->addChild(menu);
|
||||
//*/
|
||||
|
||||
// list
|
||||
CCListView *list = CCListView::viewWithMode(CCListViewModeHorizontal);
|
||||
list->setContentSize(size);
|
||||
list->setDelegate(this);
|
||||
list->setSeparatorStyle(CCListViewCellSeparatorStyleNone);
|
||||
m_pLayer->addChild(list);
|
||||
m_pList = list;
|
||||
|
||||
|
||||
// 隐藏按钮
|
||||
CCLabelTTF *labelHide = CCLabelTTF::labelWithString("Hide ", "Arial", 24);
|
||||
labelHide->setColor(ccc3(255, 0, 0));
|
||||
CCMenuItemLabel *menuItem2 = CCMenuItemLabel::itemWithLabel(labelHide, this, menu_selector(CCTextureWatcher::actionHide));
|
||||
menuItem2->setAnchorPoint(CCPoint(0, 0));
|
||||
menuItem2->setPosition(CCPoint(0, 0));
|
||||
|
||||
CCMenu *menu2 = CCMenu::menuWithItem(menuItem2);
|
||||
menu2->setAnchorPoint(CCPoint(0, 0));
|
||||
menu2->setPosition(CCPoint(size.width - menuItem2->getContentSize().width, 0));
|
||||
|
||||
m_labelHide = labelHide;
|
||||
m_menuHide = menu2;
|
||||
m_menuHide->retain();
|
||||
|
||||
// 更新按钮
|
||||
CCLabelTTF *labelFresh = CCLabelTTF::labelWithString("Fresh", "Arial", 24);
|
||||
labelFresh->setColor(ccc3(255, 0, 0));
|
||||
CCMenuItemLabel *menuItem1 = CCMenuItemLabel::itemWithLabel(labelFresh, this, menu_selector(CCTextureWatcher::actionFresh));
|
||||
menuItem1->setAnchorPoint(CCPoint(0, 0));
|
||||
menuItem1->setPosition(CCPoint(0, 0));
|
||||
|
||||
CCMenu *menu1 = CCMenu::menuWithItem(menuItem1);
|
||||
menu1->setAnchorPoint(CCPoint(0, 0));
|
||||
menu1->setPosition(CCPoint(size.width - menuItem1->getContentSize().width - menuItem2->getContentSize().width * 1.5, 0));
|
||||
m_pLayer->addChild(menu1);
|
||||
|
||||
// label page
|
||||
m_labelPage = CCLabelTTF::labelWithString(" ", CCSizeMake(size.width * 0.1, labelFresh->getContentSize().height), CCTextAlignmentCenter, "Arial", 16);
|
||||
m_labelPage->setAnchorPoint(CCPoint(0.5, 0));
|
||||
m_labelPage->setPosition(CCPoint(size.width/2.0, 0));
|
||||
m_pLayer->addChild(m_labelPage, 0);
|
||||
}
|
||||
CCTextureWatcher::~CCTextureWatcher()
|
||||
{
|
||||
if (m_menuHide)
|
||||
{
|
||||
m_menuHide->removeFromParentAndCleanup(true);
|
||||
m_menuHide->release();
|
||||
}
|
||||
|
||||
if (m_pLayer)
|
||||
{
|
||||
m_pLayer->removeFromParentAndCleanup(true);
|
||||
}
|
||||
|
||||
if (m_pTextures) m_pTextures->release();
|
||||
if (m_pszString) delete []m_pszString;
|
||||
}
|
||||
void CCTextureWatcher::actionFresh(CCObject* object)
|
||||
{
|
||||
CCTextureWatcher::sharedTextureWatcher()->fresh();
|
||||
}
|
||||
void CCTextureWatcher::actionHide(CCObject *object)
|
||||
{
|
||||
CCTextureWatcher::sharedTextureWatcher()->hide();
|
||||
}
|
||||
void CCTextureWatcher::fresh()
|
||||
{
|
||||
m_nCurrnetPage = 1;
|
||||
m_bFresh = true;
|
||||
}
|
||||
void CCTextureWatcher::hide()
|
||||
{
|
||||
m_bHide = !m_bHide;
|
||||
if (m_bHide)
|
||||
{
|
||||
m_labelHide->setString("Show");
|
||||
m_pLayer->setPosition(CCPoint(0, -m_pLayer->getContentSize().height));
|
||||
}
|
||||
else
|
||||
{
|
||||
m_labelHide->setString("Hide");
|
||||
m_pLayer->setPosition(CCPoint(0, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void CCTextureWatcher::dovisit()
|
||||
{
|
||||
if (m_bFresh)
|
||||
{
|
||||
if (m_pTextures)
|
||||
{
|
||||
m_pTextures->removeAllObjects();
|
||||
m_pTextures->release();
|
||||
}
|
||||
|
||||
CCTextureCache::sharedTextureCache()->removeUnusedTextures();
|
||||
m_pTextures = CCTextureCache::sharedTextureCache()->snapshotTextures();
|
||||
m_nTotalPage = (m_pTextures->count() + NUM_PER_PAGE - 1) / NUM_PER_PAGE;
|
||||
if (m_pTextures->count() > 0)
|
||||
{
|
||||
m_bFresh = false;
|
||||
m_pList->reload();
|
||||
}
|
||||
}
|
||||
CCNode *pParent = m_pLayer->getParent();
|
||||
if (pParent)
|
||||
{
|
||||
if (pParent != CCDirector::sharedDirector()->getRunningScene())
|
||||
{
|
||||
pParent->removeChild(m_pLayer, true);
|
||||
CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998);
|
||||
m_bFresh = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CCDirector::sharedDirector()->getRunningScene()->addChild(m_pLayer, 9998);
|
||||
}
|
||||
|
||||
pParent = m_menuHide->getParent();
|
||||
if (pParent)
|
||||
{
|
||||
if (pParent != CCDirector::sharedDirector()->getRunningScene())
|
||||
{
|
||||
pParent->removeChild(m_menuHide, true);
|
||||
CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CCDirector::sharedDirector()->getRunningScene()->addChild(m_menuHide, 9999);
|
||||
}
|
||||
}
|
||||
void CCTextureWatcher::visit(void* pSender)
|
||||
{
|
||||
CCTextureWatcher *wartcher = (CCTextureWatcher*)pSender;
|
||||
wartcher->dovisit();
|
||||
}
|
||||
|
||||
static CCTextureWatcher *g_sharedTextureWatcher = NULL;
|
||||
|
||||
CCTextureWatcher* CCTextureWatcher::sharedTextureWatcher()
|
||||
{
|
||||
if (!g_sharedTextureWatcher)
|
||||
{
|
||||
g_sharedTextureWatcher = new CCTextureWatcher();
|
||||
}
|
||||
|
||||
return g_sharedTextureWatcher;
|
||||
}
|
||||
|
||||
void CCTextureWatcher::purgeTextureWatcher()
|
||||
{
|
||||
if (g_sharedTextureWatcher != NULL)
|
||||
{
|
||||
CC_SAFE_RELEASE_NULL(g_sharedTextureWatcher);
|
||||
}
|
||||
}
|
||||
|
||||
void CCTextureWatcher::setDisplayWatcher(bool bDisplayWatcher)
|
||||
{
|
||||
m_bDisplayWatcher = bDisplayWatcher;
|
||||
if (m_bDisplayWatcher)
|
||||
{
|
||||
if (m_pszString == NULL)
|
||||
{
|
||||
m_pszString = new char[64];
|
||||
}
|
||||
CCDirector::sharedDirector()->setWatcherCallbackFun(this, &CCTextureWatcher::visit);
|
||||
}
|
||||
else
|
||||
{
|
||||
CCDirector::sharedDirector()->setWatcherCallbackFun(NULL, NULL);
|
||||
purgeTextureWatcher();
|
||||
}
|
||||
}
|
||||
|
||||
void CCTextureWatcher::CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data)
|
||||
{
|
||||
data->nNumberOfRows = m_nTotalPage;
|
||||
}
|
||||
|
||||
void CCTextureWatcher::CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data)
|
||||
{
|
||||
m_nCurrnetPage = data->nRow + 1;
|
||||
CCListViewCell *cell = CCListViewCell::node();
|
||||
cell->setOpacity(0);
|
||||
cell->setContentSize(m_pList->getContentSize());
|
||||
cell->setSelectionColor(ccc4(0, 0, 0, 0));
|
||||
data->cell = cell;
|
||||
|
||||
CCSize listItemSize = CCSize(m_pList->getContentSize().width / NUM_PER_PAGE, m_pList->getContentSize().height);
|
||||
|
||||
CCSize size = CCSize(listItemSize.width * 0.9, listItemSize.height * 0.6);
|
||||
|
||||
sprintf(m_pszString, "%d/%d", m_nCurrnetPage, m_nTotalPage);
|
||||
m_labelPage->setString(m_pszString);
|
||||
|
||||
float offX = 0, offY = 0, offsetX = 0, offsetY = 0;
|
||||
CC_UNUSED_PARAM(offsetY);
|
||||
int nCount = 0;
|
||||
int nStart = (m_nCurrnetPage - 1) * NUM_PER_PAGE;
|
||||
int nEnd = nStart + NUM_PER_PAGE;
|
||||
|
||||
CCDictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(m_pTextures, pElement)
|
||||
{
|
||||
if (nCount >= nStart && nCount < nEnd)
|
||||
{
|
||||
string key = pElement->getStrKey();
|
||||
CCTexture2D* textrue = (CCTexture2D*)pElement->getObject();
|
||||
//textrue = m_pTextures->objectForKey(*it);
|
||||
if (textrue)
|
||||
{
|
||||
// 引用数
|
||||
sprintf(m_pszString, "[%d]", textrue->retainCount() - 2);
|
||||
CCLabelTTF *labelCount = CCLabelTTF::labelWithString(m_pszString, "Arial", 16);
|
||||
if (textrue->retainCount() - 2 > 0)
|
||||
{
|
||||
labelCount->setColor(ccc3(0, 255, 0));
|
||||
}
|
||||
else
|
||||
{
|
||||
labelCount->setColor(ccc3(255, 0, 0));
|
||||
}
|
||||
offX = offsetX + listItemSize.width * 0.5 - labelCount->getContentSize().width * 0.5;
|
||||
offY = (listItemSize.height - size.height) * 0.5 - labelCount->getContentSize().height;
|
||||
labelCount->setPosition(CCPoint(offX, offY));
|
||||
labelCount->setAnchorPoint(CCPoint(0, 0));
|
||||
cell->addChild(labelCount);
|
||||
|
||||
// 大小
|
||||
sprintf(m_pszString, "%.0f*%.0f", textrue->getContentSize().width, textrue->getContentSize().height);
|
||||
CCLabelTTF *labelSize = CCLabelTTF::labelWithString(m_pszString, "Arial", 16);
|
||||
offX = offsetX + listItemSize.width * 0.5;
|
||||
offY = (listItemSize.height - size.height) * 0.5 + size.height;
|
||||
labelSize->setPosition(CCPoint(offX, offY));
|
||||
labelSize->setAnchorPoint(CCPoint(0.5, 0));
|
||||
cell->addChild(labelSize);
|
||||
|
||||
// 名称
|
||||
int len = key.length();
|
||||
int pos = 0;
|
||||
#if defined(ND_MAC) || defined(ND_IPHONE)
|
||||
pos = key.rfind('/') + 1;
|
||||
#else
|
||||
pos = key.rfind('\\') + 1;
|
||||
int pos2 = key.rfind('/') + 1;
|
||||
pos = pos > pos2 ? pos : pos2;
|
||||
#endif
|
||||
string name = key.substr(pos, len - pos);
|
||||
sprintf(m_pszString, "%s", name.c_str());
|
||||
CCSize dimensions = CCSizeMake(listItemSize.width * 0.9, labelSize->getContentSize().height);
|
||||
CCLabelTTF *labelName = CCLabelTTF::labelWithString(m_pszString, dimensions, CCTextAlignmentCenter, "Arial", 16);
|
||||
offX = offsetX + listItemSize.width * 0.5;
|
||||
offY = offY + labelName->getContentSize().height;
|
||||
labelName->setPosition(CCPoint(offX, offY));
|
||||
labelName->setAnchorPoint(CCPoint(0.5, 0));
|
||||
cell->addChild(labelName);
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithTexture(textrue);
|
||||
sprite->setAnchorPoint(CCPoint(0, 0));
|
||||
|
||||
CCSize spriteSize = sprite->getContentSize();
|
||||
float scale;
|
||||
if (spriteSize.width < size.width && spriteSize.height < size.height)
|
||||
{
|
||||
scale = 1;
|
||||
}
|
||||
else if (spriteSize.width * size.height >= spriteSize.height * size.width)
|
||||
{
|
||||
scale = size.width / spriteSize.width;
|
||||
}
|
||||
else
|
||||
{
|
||||
scale = size.height / spriteSize.height;
|
||||
}
|
||||
sprite->setScale(scale);
|
||||
spriteSize.width *= scale;
|
||||
spriteSize.height *= scale;
|
||||
offX = offsetX + (listItemSize.width - spriteSize.width) * 0.5;
|
||||
offY = (listItemSize.height - spriteSize.height) * 0.5;
|
||||
sprite->setPosition(CCPoint(offX, offY));
|
||||
cell->addChild(sprite);
|
||||
offsetX += listItemSize.width;
|
||||
}
|
||||
}
|
||||
++nCount;
|
||||
}
|
||||
}
|
||||
|
||||
void CCTextureWatcher::CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CCTextureWatcher::CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NS_CC_EXT_END
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef __CCMEMLAYER_H__
|
||||
#define __CCMEMLAYER_H__
|
||||
|
||||
#include "extensions/CCListView/CCListView.h"
|
||||
|
||||
namespace cocos2d { class CCDictionary; }
|
||||
namespace cocos2d { class CCLabelTTF; }
|
||||
namespace cocos2d { class CCMenu; }
|
||||
namespace cocos2d { class CCLayerColor; }
|
||||
|
||||
|
||||
NS_CC_EXT_BEGIN
|
||||
|
||||
class CC_DLL CCTextureWatcher :public CCObject, public CCListViewDelegate
|
||||
{
|
||||
private:
|
||||
CCTextureWatcher();
|
||||
public:
|
||||
virtual ~CCTextureWatcher();
|
||||
|
||||
static CCTextureWatcher* sharedTextureWatcher();
|
||||
static void purgeTextureWatcher();
|
||||
void setDisplayWatcher(bool bDisplayWatcher);
|
||||
void fresh(void);
|
||||
protected:
|
||||
void actionFresh(CCObject* object);
|
||||
void actionHide(CCObject* object);
|
||||
void hide(void);
|
||||
void dovisit(void);
|
||||
static void visit(void* pSender);
|
||||
protected:
|
||||
virtual void CCListView_numberOfCells(CCListView *listView, CCListViewProtrolData *data);
|
||||
virtual void CCListView_cellForRow(CCListView *listView, CCListViewProtrolData *data);
|
||||
virtual void CCListView_didClickCellAtRow(CCListView *listView, CCListViewProtrolData *data);
|
||||
virtual void CCListView_didScrollToRow(CCListView *listView, CCListViewProtrolData *data);
|
||||
private:
|
||||
bool m_bDisplayWatcher;
|
||||
bool m_bFresh;
|
||||
bool m_bHide;
|
||||
CCDictionary *m_pTextures;
|
||||
char *m_pszString;
|
||||
int m_nCurrnetPage;
|
||||
int m_nTotalPage;
|
||||
CCLabelTTF *m_labelHide;
|
||||
CCLabelTTF *m_labelPage;
|
||||
CCMenu *m_menuHide;
|
||||
CCLayerColor *m_pLayer;
|
||||
CCListView *m_pList;
|
||||
};
|
||||
|
||||
NS_CC_EXT_END
|
||||
|
||||
#endif
|
|
@ -3,5 +3,7 @@
|
|||
|
||||
#include "extensions/CCNotificationCenter/CCNotificationCenter.h"
|
||||
#include "extensions/CCControlExtension/CCControlExtensions.h"
|
||||
#include "extensions/CCListView/CCListView.h"
|
||||
#include "extensions/CCTextureWatcher/CCTextureWatcher.h"
|
||||
|
||||
#endif /* __COCOS2DEXT_H__ */
|
||||
|
|
|
@ -67,7 +67,7 @@ bool CCParticleSystemQuad::initWithTotalParticles(unsigned int numberOfParticles
|
|||
|
||||
|
||||
// Need to listen the event only when not use batchnode, because it will use VBO
|
||||
CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
|
||||
extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
|
||||
callfuncO_selector(CCParticleSystemQuad::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
NULL);
|
||||
|
@ -99,7 +99,7 @@ CCParticleSystemQuad::~CCParticleSystemQuad()
|
|||
#endif
|
||||
}
|
||||
|
||||
CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
}
|
||||
|
||||
// implementation CCParticleSystemQuad
|
||||
|
|
|
@ -157,15 +157,6 @@ public:
|
|||
static void setIsPopupNotify(bool bNotify);
|
||||
static bool getIsPopupNotify();
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// interfaces on wophone
|
||||
///////////////////////////////////////////////////
|
||||
/**
|
||||
@brief Set the resource zip file name
|
||||
@param pszZipFileName The relative path of the .zip file
|
||||
*/
|
||||
static void setResource(const char* pszZipFileName);
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
// interfaces on ios
|
||||
///////////////////////////////////////////////////
|
||||
|
|
|
@ -59,10 +59,16 @@ It's new in cocos2d-x since v0.99.5
|
|||
#define NS_CC_BEGIN namespace cocos2d {
|
||||
#define NS_CC_END }
|
||||
#define USING_NS_CC using namespace cocos2d
|
||||
#define NS_CC_EXT_BEGIN namespace cocos2d { namespace extension {
|
||||
#define NS_CC_EXT_END }}
|
||||
#define USING_NS_CC_EXT using namespace cocos2d::extension
|
||||
#else
|
||||
#define NS_CC_BEGIN
|
||||
#define NS_CC_END
|
||||
#define USING_NS_CC
|
||||
#define NS_CC_EXT_BEGIN
|
||||
#define NS_CC_EXT_END
|
||||
#define USING_NS_CC_EXT
|
||||
#endif
|
||||
|
||||
/** CC_PROPERTY_READONLY is used to declare a protected variable.
|
||||
|
|
|
@ -118,11 +118,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
return pData;
|
||||
}
|
||||
|
||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
int CCFileUtils::ccLoadFileIntoMemory(const char *filename, unsigned char **out)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
|
|
|
@ -475,10 +475,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
}
|
||||
return pBuffer;
|
||||
}
|
||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||
{
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
// notification support when getFileData from a invalid file
|
||||
static bool s_bPopupNotify = true;
|
||||
|
|
|
@ -193,12 +193,6 @@ unsigned char* CCFileUtils::getFileData(const char* pszFileName, const char* psz
|
|||
return pBuffer;
|
||||
}
|
||||
|
||||
void CCFileUtils::setResource(const char* pszZipFileName)
|
||||
{
|
||||
CC_UNUSED_PARAM(pszZipFileName);
|
||||
CCAssert(0, "Have not implement!");
|
||||
}
|
||||
|
||||
string CCFileUtils::getWriteablePath()
|
||||
{
|
||||
// return the path that the exe file saved in
|
||||
|
|
|
@ -1195,6 +1195,42 @@
|
|||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="CCTextureWatcher"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\extensions\CCTextureWatcher\CCTextureWatcher.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\extensions\CCTextureWatcher\CCTextureWatcher.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="CCListView"
|
||||
>
|
||||
<File
|
||||
RelativePath="..\extensions\CCListView\CCControlDefine.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\extensions\CCListView\CCListView.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\extensions\CCListView\CCListView.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\extensions\CCListView\CCListViewCell.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\extensions\CCListView\CCListViewCell.h"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Filter>
|
||||
<Filter
|
||||
Name="kazmath"
|
||||
|
|
|
@ -64,7 +64,7 @@ CCTextureAtlas::~CCTextureAtlas()
|
|||
#endif
|
||||
CC_SAFE_RELEASE(m_pTexture);
|
||||
|
||||
CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
extension::CCNotificationCenter::sharedNotificationCenter()->removeObserver(this, EVNET_COME_TO_FOREGROUND);
|
||||
}
|
||||
|
||||
unsigned int CCTextureAtlas::getTotalQuads()
|
||||
|
@ -177,7 +177,7 @@ bool CCTextureAtlas::initWithTexture(CCTexture2D *texture, unsigned int capacity
|
|||
memset( m_pIndices, 0, m_uCapacity * 6 * sizeof(GLushort) );
|
||||
|
||||
// listen the event when app go to background
|
||||
CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
|
||||
extension::CCNotificationCenter::sharedNotificationCenter()->addObserver(this,
|
||||
callfuncO_selector(CCTextureAtlas::listenBackToForeground),
|
||||
EVNET_COME_TO_FOREGROUND,
|
||||
NULL);
|
||||
|
|
|
@ -195,6 +195,17 @@ const char* CCTextureCache::description()
|
|||
return CCString::stringWithFormat("<CCTextureCache | Number of textures = %u>", m_pTextures->count())->getCString();
|
||||
}
|
||||
|
||||
CCDictionary* CCTextureCache::snapshotTextures()
|
||||
{
|
||||
CCDictionary* pRet = new CCDictionary();
|
||||
CCDictElement* pElement = NULL;
|
||||
CCDICT_FOREACH(m_pTextures, pElement)
|
||||
{
|
||||
pRet->setObject(pElement->getObject(), pElement->getStrKey());
|
||||
}
|
||||
return pRet;
|
||||
}
|
||||
|
||||
void CCTextureCache::addImageAsync(const char *path, CCObject *target, SEL_CallFuncO selector)
|
||||
{
|
||||
CCAssert(path != NULL, "TextureCache: fileimage MUST not be NULL");
|
||||
|
|
|
@ -65,6 +65,8 @@ public:
|
|||
|
||||
const char* description(void);
|
||||
|
||||
CCDictionary* snapshotTextures();
|
||||
|
||||
/** Retruns ths shared instance of the cache */
|
||||
static CCTextureCache * sharedTextureCache();
|
||||
|
||||
|
|
|
@ -1,81 +0,0 @@
|
|||
set fso = Wscript.CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
dim szPrompt, msgRet
|
||||
szPrompt = "Prompt"
|
||||
|
||||
function ReplaceFileContent(fileName, oldStr, newStr)
|
||||
set f = fso.opentextfile(fileName)
|
||||
s = replace(f.readall, oldStr, newStr)
|
||||
f.close
|
||||
set r = fso.opentextfile(fileName, 2, true)
|
||||
r.write s
|
||||
end function
|
||||
|
||||
function CopyFolder(srcFolder, desFolder)
|
||||
if (fso.FolderExists(desFolder)) then
|
||||
'msgbox("none:"+srcFolder+":"+desFolder)
|
||||
'If the desFolder exist, do nothing.
|
||||
else
|
||||
CopyFolder = fso.CopyFolder(srcFolder, desFolder)
|
||||
end if
|
||||
end function
|
||||
|
||||
function ConfigureProject()
|
||||
dim szProjectName
|
||||
szProjectName = Inputbox("Please Input Project Name:", szPrompt)
|
||||
|
||||
if szProjectName = "" then
|
||||
Wscript.quit
|
||||
end if
|
||||
|
||||
if (0 = strcomp(szProjectName, "HelloWorld", 1) or 0 = strcomp(szProjectName, "tests", 1)) then
|
||||
msgRet = msgbox("Can not create a project named with "+szProjectName+", Please input again!", 1, szPrompt)
|
||||
if (msgRet = 1) then
|
||||
call ConfigureProject
|
||||
end if
|
||||
Wscript.quit
|
||||
end if
|
||||
|
||||
if (fso.FolderExists(szProjectName)) then
|
||||
else
|
||||
fso.CreateFolder(szProjectName)
|
||||
end if
|
||||
|
||||
dim badaFolder
|
||||
badaFolder = szProjectName + "\bada"
|
||||
if (fso.FolderExists(badaFolder)) then
|
||||
msgRet = msgbox("The '"+szProjectName+"' project exists, can't override! Please input again!", 1, szPrompt)
|
||||
if (msgRet = 1) then
|
||||
call ConfigureProject
|
||||
end if
|
||||
Wcript.quit
|
||||
end if
|
||||
|
||||
dim szSrcClass, szSrcBada, szSrcResource
|
||||
dim szDesClass, szDesBada, szDesResource
|
||||
|
||||
szSrcClass = "HelloWorld\Classes"
|
||||
szSrcBada = "HelloWorld\bada"
|
||||
szSrcResource = "HelloWorld\Resources"
|
||||
|
||||
szDesClass = szProjectName+"\Classes"
|
||||
szDesBada = szProjectName+"\bada"
|
||||
szDesResource = szProjectName+"\Resources"
|
||||
|
||||
call CopyFolder(szSrcClass, szDesClass)
|
||||
call CopyFolder(szSrcBada, szDesBada)
|
||||
call CopyFolder(szSrcResource, szDesResource)
|
||||
|
||||
dim i
|
||||
for i=1 to 2
|
||||
call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\application.xml", "HelloWorld", szProjectName)
|
||||
call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\.project", "HelloWorld", szProjectName)
|
||||
call ReplaceFileContent(szProjectName+"\bada\sdk"+cstr(i)+".0\.cproject", "HelloWorld", szProjectName)
|
||||
next
|
||||
|
||||
call msgbox("Congratulations, the '"+szProjectName+"' project have been created successfully, please use Bada IDE to import the project!", 0, szPrompt)
|
||||
|
||||
end function
|
||||
|
||||
call ConfigureProject
|
||||
Wscript.quit
|
|
@ -1,9 +0,0 @@
|
|||
#!/bin/bash
|
||||
# This script should be called by create-android-project.bat
|
||||
# or should be runned in linux shell. It can not be runned under
|
||||
# cygwin.
|
||||
# Don't modify the script until you know what you do.
|
||||
|
||||
# set environment paramters
|
||||
|
||||
bash `pwd`/create-android-project.sh -linux $@
|
|
@ -1,83 +0,0 @@
|
|||
#!/bin/sh
|
||||
|
||||
HELLOWORLD_ROOT=`pwd`/HelloWorld
|
||||
|
||||
# make directory qnx and copy all files and directories into it
|
||||
copy_qnx_folder(){
|
||||
if [ -d $PROJECT_DIR/qnx ]; then
|
||||
echo "The '$PROJECT_NAME' project exists, can't override! Please input again!"
|
||||
create_qnx_project
|
||||
exit
|
||||
fi
|
||||
mkdir $PROJECT_DIR/qnx
|
||||
echo $HELLOWORLD_ROOT
|
||||
for file in `ls -a $HELLOWORLD_ROOT/qnx | grep -E '\.(project|cproject|xml|png|cpp)' `
|
||||
do
|
||||
file=$HELLOWORLD_ROOT/qnx/$file
|
||||
if [ -f $file ];then
|
||||
#echo $file
|
||||
cp $file $PROJECT_DIR/qnx
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
copy_cpp_h_from_helloworld(){
|
||||
if [ -d $PROJECT_DIR/Classes ]; then
|
||||
echo "Classes folder exists, skip copying Classes folder!"
|
||||
else
|
||||
mkdir $PROJECT_DIR/Classes
|
||||
for file in `ls $HELLOWORLD_ROOT/Classes/* | grep -E '.(cpp|h|mk)' `
|
||||
do
|
||||
if [ -f $file ];then
|
||||
#echo $file
|
||||
cp $file $PROJECT_DIR/Classes
|
||||
fi
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# copy resources
|
||||
copy_resouces(){
|
||||
if [ -d $PROJECT_DIR/Resources ]; then
|
||||
echo "Resources folder exists, skip copying Resources folder!"
|
||||
else
|
||||
mkdir $PROJECT_DIR/Resources
|
||||
|
||||
for file in $HELLOWORLD_ROOT/Resources/*
|
||||
do
|
||||
#echo $file
|
||||
cp $file $PROJECT_DIR/Resources
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
# replace string
|
||||
modify_file_content(){
|
||||
# here should use # instead of /, why??
|
||||
sed "s#HelloWorld#$PROJECT_NAME#" $PROJECT_DIR/qnx/$1 > $PROJECT_DIR/qnx/tmp.txt
|
||||
rm $PROJECT_DIR/qnx/$1
|
||||
mv $PROJECT_DIR/qnx/tmp.txt $PROJECT_DIR/qnx/$1
|
||||
}
|
||||
|
||||
create_qnx_project(){
|
||||
echo "Please input your project name:"
|
||||
read PROJECT_NAME
|
||||
PROJECT_DIR=`pwd`/$PROJECT_NAME
|
||||
|
||||
# check if PROJECT_DIR is exist
|
||||
if [ -d $PROJECT_DIR ]; then
|
||||
echo ""
|
||||
else
|
||||
mkdir $PROJECT_DIR
|
||||
fi
|
||||
|
||||
copy_qnx_folder
|
||||
modify_file_content .project
|
||||
modify_file_content .cproject
|
||||
modify_file_content bar-descriptor.xml
|
||||
copy_cpp_h_from_helloworld
|
||||
copy_resouces
|
||||
echo "Congratulations, the '$PROJECT_NAME' project have been created successfully, please use QNX IDE to import the project!"
|
||||
}
|
||||
|
||||
create_qnx_project
|
|
@ -1,78 +0,0 @@
|
|||
set fso = Wscript.CreateObject("Scripting.FileSystemObject")
|
||||
|
||||
dim szPrompt, msgRet
|
||||
szPrompt = "Prompt"
|
||||
|
||||
function ReplaceFileContent(fileName, oldStr, newStr)
|
||||
set f = fso.opentextfile(fileName)
|
||||
s = replace(f.readall, oldStr, newStr)
|
||||
f.close
|
||||
set r = fso.opentextfile(fileName, 2, true)
|
||||
r.write s
|
||||
end function
|
||||
|
||||
function CopyFolder(srcFolder, desFolder)
|
||||
if (fso.FolderExists(desFolder)) then
|
||||
'msgbox("none:"+srcFolder+":"+desFolder)
|
||||
'If the desFolder exist, do nothing.
|
||||
else
|
||||
CopyFolder = fso.CopyFolder(srcFolder, desFolder)
|
||||
end if
|
||||
end function
|
||||
|
||||
function ConfigureProject()
|
||||
dim szProjectName
|
||||
szProjectName = Inputbox("Please Input Project Name:", szPrompt)
|
||||
|
||||
if szProjectName = "" then
|
||||
Wscript.quit
|
||||
end if
|
||||
|
||||
if (0 = strcomp(szProjectName, "HelloWorld", 1) or 0 = strcomp(szProjectName, "tests", 1)) then
|
||||
msgRet = msgbox("Can not create a project named with "+szProjectName+", Please input again!", 1, szPrompt)
|
||||
if (msgRet = 1) then
|
||||
call ConfigureProject
|
||||
end if
|
||||
Wscript.quit
|
||||
end if
|
||||
|
||||
if (fso.FolderExists(szProjectName)) then
|
||||
else
|
||||
fso.CreateFolder(szProjectName)
|
||||
end if
|
||||
|
||||
dim qnxFolder
|
||||
qnxFolder = szProjectName + "\qnx"
|
||||
if (fso.FolderExists(qnxFolder)) then
|
||||
msgRet = msgbox("The '"+szProjectName+"' project exists, can't override! Please input again!", 1, szPrompt)
|
||||
if (msgRet = 1) then
|
||||
call ConfigureProject
|
||||
end if
|
||||
Wcript.quit
|
||||
end if
|
||||
|
||||
dim szSrcClass, szSrcQnx, szSrcResource
|
||||
dim szDesClass, szDesQnx, szDesResource
|
||||
|
||||
szSrcClass = "HelloWorld\Classes"
|
||||
szSrcQnx = "HelloWorld\qnx"
|
||||
szSrcResource = "HelloWorld\Resources"
|
||||
|
||||
szDesClass = szProjectName+"\Classes"
|
||||
szDesQnx = szProjectName+"\qnx"
|
||||
szDesResource = szProjectName+"\Resources"
|
||||
|
||||
call CopyFolder(szSrcClass, szDesClass)
|
||||
call CopyFolder(szSrcQnx, szDesQnx)
|
||||
call CopyFolder(szSrcResource, szDesResource)
|
||||
|
||||
call ReplaceFileContent(szProjectName+"\qnx\bar-descriptor.xml", "HelloWorld", szProjectName)
|
||||
call ReplaceFileContent(szProjectName+"\qnx\.project", "HelloWorld", szProjectName)
|
||||
call ReplaceFileContent(szProjectName+"\qnx\.cproject", "HelloWorld", szProjectName)
|
||||
|
||||
call msgbox("Congratulations, the '"+szProjectName+"' project have been created successfully, please use QNX IDE to import the project!", 0, szPrompt)
|
||||
|
||||
end function
|
||||
|
||||
call ConfigureProject
|
||||
Wscript.quit
|
|
@ -47,11 +47,6 @@ bool AppDelegate::initInstance()
|
|||
// 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_MARMALADE)
|
||||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
||||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
#endif
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
|
@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayFPS(true);
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
|
|
@ -34,7 +34,7 @@ bool HelloWorld::init()
|
|||
// you may modify it.
|
||||
|
||||
// add a "close" icon to exit the progress. it's an autorelease object
|
||||
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemFromNormalImage(
|
||||
CCMenuItemImage *pCloseItem = CCMenuItemImage::itemWithNormalImage(
|
||||
"CloseNormal.png",
|
||||
"CloseSelected.png",
|
||||
this,
|
||||
|
|
|
@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication;
|
|||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
|
|
|
@ -47,11 +47,6 @@ bool AppDelegate::initInstance()
|
|||
// 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_MARMALADE)
|
||||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
||||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
#endif
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
|
@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayFPS(true);
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
|
|
@ -12,87 +12,84 @@ using namespace cocos2d;
|
|||
using namespace CocosDenshion;
|
||||
|
||||
#define PTM_RATIO 32
|
||||
enum
|
||||
{
|
||||
kTagTileMap = 1,
|
||||
kTagSpriteManager = 1,
|
||||
kTagAnimation1 = 1,
|
||||
|
||||
enum {
|
||||
kTagParentNode = 1,
|
||||
};
|
||||
|
||||
PhysicsSprite::PhysicsSprite()
|
||||
: m_pBody(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void PhysicsSprite::setPhysicsBody(b2Body * body)
|
||||
{
|
||||
m_pBody = body;
|
||||
}
|
||||
|
||||
// this method will only get called if the sprite is batched.
|
||||
// return YES if the physics values (angles, position ) changed
|
||||
// If you return NO, then nodeToParentTransform won't be called.
|
||||
bool PhysicsSprite::isDirty(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// returns the transform matrix according the Chipmunk Body values
|
||||
CCAffineTransform PhysicsSprite::nodeToParentTransform(void)
|
||||
{
|
||||
b2Vec2 pos = m_pBody->GetPosition();
|
||||
|
||||
float x = pos.x * PTM_RATIO;
|
||||
float y = pos.y * PTM_RATIO;
|
||||
|
||||
if ( !getIsRelativeAnchorPoint() ) {
|
||||
x += m_tAnchorPointInPoints.x;
|
||||
y += m_tAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Make matrix
|
||||
float radians = m_pBody->GetAngle();
|
||||
float c = cosf(radians);
|
||||
float s = sinf(radians);
|
||||
|
||||
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){
|
||||
x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y;
|
||||
y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Rot, Translate Matrix
|
||||
m_tTransform = CCAffineTransformMake( c, s,
|
||||
-s, c,
|
||||
x, y );
|
||||
|
||||
return m_tTransform;
|
||||
}
|
||||
|
||||
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);
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
// init physics
|
||||
this->initPhysics();
|
||||
|
||||
// Define the gravity vector.
|
||||
b2Vec2 gravity;
|
||||
gravity.Set(0.0f, -10.0f);
|
||||
CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 100);
|
||||
m_pSpriteTexture = parent->getTexture();
|
||||
|
||||
// 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);
|
||||
world->SetAllowSleeping(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);
|
||||
*/
|
||||
|
||||
b2BodyDef groundBodyDef;
|
||||
groundBodyDef.position.Set(screenSize.width/2/PTM_RATIO,
|
||||
screenSize.height/2/PTM_RATIO); // 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.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, -screenSize.height/2/PTM_RATIO), 0);
|
||||
groundBody->CreateFixture(&groundBox, 0);
|
||||
|
||||
// top
|
||||
groundBox.SetAsBox(screenSize.width/2/PTM_RATIO, 0, b2Vec2(0, screenSize.height/2/PTM_RATIO), 0);
|
||||
groundBody->CreateFixture(&groundBox, 0);
|
||||
|
||||
// left
|
||||
groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(-screenSize.width/2/PTM_RATIO, 0), 0);
|
||||
groundBody->CreateFixture(&groundBox, 0);
|
||||
|
||||
// right
|
||||
groundBox.SetAsBox(0, screenSize.height/2/PTM_RATIO, b2Vec2(screenSize.width/2/PTM_RATIO, 0), 0);
|
||||
groundBody->CreateFixture(&groundBox, 0);
|
||||
addChild(parent, 0, kTagParentNode);
|
||||
|
||||
|
||||
//Set up sprite
|
||||
CCSpriteBatchNode *mgr = CCSpriteBatchNode::batchNodeWithFile("blocks.png", 150);
|
||||
addChild(mgr, 0, kTagSpriteManager);
|
||||
|
||||
addNewSpriteWithCoords( CCPointMake(screenSize.width/2, screenSize.height/2) );
|
||||
addNewSpriteAtPosition(ccp(s.width/2, s.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) );
|
||||
label->setColor(ccc3(0,0,255));
|
||||
label->setPosition(ccp( s.width/2, s.height-50));
|
||||
|
||||
schedule( schedule_selector(HelloWorld::tick) );
|
||||
scheduleUpdate();
|
||||
}
|
||||
|
||||
HelloWorld::~HelloWorld()
|
||||
|
@ -103,35 +100,94 @@ HelloWorld::~HelloWorld()
|
|||
//delete m_debugDraw;
|
||||
}
|
||||
|
||||
void HelloWorld::draw()
|
||||
void HelloWorld::initPhysics()
|
||||
{
|
||||
// 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();
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
// restore default GL states
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnableClientState(GL_COLOR_ARRAY);
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
b2Vec2 gravity;
|
||||
gravity.Set(0.0f, -10.0f);
|
||||
world = new b2World(gravity);
|
||||
|
||||
// Do we want to let bodies sleep?
|
||||
world->SetAllowSleeping(true);
|
||||
|
||||
world->SetContinuousPhysics(true);
|
||||
|
||||
// m_debugDraw = new GLESDebugDraw( PTM_RATIO );
|
||||
// world->SetDebugDraw(m_debugDraw);
|
||||
|
||||
uint32 flags = 0;
|
||||
flags += b2Draw::e_shapeBit;
|
||||
// flags += b2Draw::e_jointBit;
|
||||
// flags += b2Draw::e_aabbBit;
|
||||
// flags += b2Draw::e_pairBit;
|
||||
// flags += b2Draw::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.
|
||||
b2EdgeShape groundBox;
|
||||
|
||||
// bottom
|
||||
|
||||
groundBox.Set(b2Vec2(0,0), b2Vec2(s.width/PTM_RATIO,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// top
|
||||
groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// left
|
||||
groundBox.Set(b2Vec2(0,s.height/PTM_RATIO), b2Vec2(0,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
|
||||
// right
|
||||
groundBox.Set(b2Vec2(s.width/PTM_RATIO,s.height/PTM_RATIO), b2Vec2(s.width/PTM_RATIO,0));
|
||||
groundBody->CreateFixture(&groundBox,0);
|
||||
}
|
||||
|
||||
void HelloWorld::addNewSpriteWithCoords(CCPoint p)
|
||||
void HelloWorld::draw()
|
||||
{
|
||||
//UXLOG(L"Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
CCSpriteBatchNode* sheet = (CCSpriteBatchNode*)getChildByTag(kTagSpriteManager);
|
||||
//
|
||||
// IMPORTANT:
|
||||
// This is only for debug purposes
|
||||
// It is recommend to disable it
|
||||
//
|
||||
CCLayer::draw();
|
||||
|
||||
ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
|
||||
|
||||
kmGLPushMatrix();
|
||||
|
||||
world->DrawDebugData();
|
||||
|
||||
kmGLPopMatrix();
|
||||
}
|
||||
|
||||
void HelloWorld::addNewSpriteAtPosition(CCPoint p)
|
||||
{
|
||||
CCLOG("Add sprite %0.2f x %02.f",p.x,p.y);
|
||||
CCNode* parent = getChildByTag(kTagParentNode);
|
||||
|
||||
//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);
|
||||
PhysicsSprite *sprite = new PhysicsSprite();
|
||||
sprite->initWithTexture(m_pSpriteTexture, CCRectMake(32 * idx,32 * idy,32,32));
|
||||
sprite->autorelease();
|
||||
|
||||
CCSprite *sprite = CCSprite::spriteWithBatchNode(sheet, CCRectMake(32 * idx,32 * idy,32,32));
|
||||
sheet->addChild(sprite);
|
||||
parent->addChild(sprite);
|
||||
|
||||
sprite->setPosition( CCPointMake( p.x, p.y) );
|
||||
|
||||
|
@ -140,7 +196,7 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p)
|
|||
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.
|
||||
|
@ -153,10 +209,12 @@ void HelloWorld::addNewSpriteWithCoords(CCPoint p)
|
|||
fixtureDef.density = 1.0f;
|
||||
fixtureDef.friction = 0.3f;
|
||||
body->CreateFixture(&fixtureDef);
|
||||
|
||||
sprite->setPhysicsBody(body);
|
||||
}
|
||||
|
||||
|
||||
void HelloWorld::tick(ccTime dt)
|
||||
void HelloWorld::update(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.
|
||||
|
@ -195,11 +253,11 @@ void HelloWorld::ccTouchesEnded(CCSet* touches, CCEvent* event)
|
|||
if(!touch)
|
||||
break;
|
||||
|
||||
CCPoint location = touch->locationInView(touch->view());
|
||||
CCPoint location = touch->locationInView();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
|
||||
addNewSpriteWithCoords( location );
|
||||
addNewSpriteAtPosition( location );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,17 @@
|
|||
#include "cocos2d.h"
|
||||
#include "Box2D.h"
|
||||
|
||||
class PhysicsSprite : public cocos2d::CCSprite
|
||||
{
|
||||
public:
|
||||
PhysicsSprite();
|
||||
void setPhysicsBody(b2Body * body);
|
||||
virtual bool isDirty(void);
|
||||
virtual cocos2d::CCAffineTransform nodeToParentTransform(void);
|
||||
private:
|
||||
b2Body* m_pBody; // strong ref
|
||||
};
|
||||
|
||||
class HelloWorld : public cocos2d::CCLayer {
|
||||
public:
|
||||
~HelloWorld();
|
||||
|
@ -20,14 +31,17 @@ public:
|
|||
// returns a Scene that contains the HelloWorld as the only child
|
||||
static cocos2d::CCScene* scene();
|
||||
|
||||
void initPhysics();
|
||||
// adds a new sprite at a given coordinate
|
||||
void addNewSpriteWithCoords(cocos2d::CCPoint p);
|
||||
void addNewSpriteAtPosition(cocos2d::CCPoint p);
|
||||
|
||||
virtual void draw();
|
||||
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
|
||||
void tick(cocos2d::ccTime dt);
|
||||
void update(cocos2d::ccTime dt);
|
||||
|
||||
private:
|
||||
b2World* world;
|
||||
cocos2d::CCTexture2D* m_pSpriteTexture; // weak ref
|
||||
};
|
||||
|
||||
#endif // __HELLO_WORLD_H__
|
||||
|
|
|
@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication;
|
|||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
|
|
|
@ -47,11 +47,6 @@ bool AppDelegate::initInstance()
|
|||
// 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_MARMALADE)
|
||||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
||||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
#endif
|
||||
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
|
@ -70,7 +65,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayFPS(true);
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// set FPS. the default value is 1.0/60 if you don't call this
|
||||
pDirector->setAnimationInterval(1.0 / 60);
|
||||
|
|
|
@ -14,25 +14,65 @@ using namespace cocos2d;
|
|||
using namespace CocosDenshion;
|
||||
|
||||
enum {
|
||||
kTagBatchNode = 1,
|
||||
kTagParentNode = 1,
|
||||
};
|
||||
|
||||
static void
|
||||
eachShape(void *ptr, void* unused)
|
||||
// callback to remove Shapes from the Space
|
||||
void removeShape( cpBody *body, cpShape *shape, void *data )
|
||||
{
|
||||
cpShape *shape = (cpShape*) ptr;
|
||||
CCSprite *sprite = (CCSprite*)shape->data;
|
||||
if( sprite )
|
||||
{
|
||||
cpBody *body = shape->body;
|
||||
cpShapeFree( shape );
|
||||
}
|
||||
|
||||
// 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));
|
||||
ChipmunkPhysicsSprite::ChipmunkPhysicsSprite()
|
||||
: m_pBody(NULL)
|
||||
{
|
||||
|
||||
sprite->setRotation((float) CC_RADIANS_TO_DEGREES( -body->a ));
|
||||
}
|
||||
}
|
||||
|
||||
ChipmunkPhysicsSprite::~ChipmunkPhysicsSprite()
|
||||
{
|
||||
cpBodyEachShape(m_pBody, removeShape, NULL);
|
||||
cpBodyFree( m_pBody );
|
||||
}
|
||||
|
||||
void ChipmunkPhysicsSprite::setPhysicsBody(cpBody * body)
|
||||
{
|
||||
m_pBody = body;
|
||||
}
|
||||
|
||||
// this method will only get called if the sprite is batched.
|
||||
// return YES if the physics values (angles, position ) changed
|
||||
// If you return NO, then nodeToParentTransform won't be called.
|
||||
bool ChipmunkPhysicsSprite::isDirty(void)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void)
|
||||
{
|
||||
CCFloat x = m_pBody->p.x;
|
||||
CCFloat y = m_pBody->p.y;
|
||||
|
||||
if ( !getIsRelativeAnchorPoint() ) {
|
||||
x += m_tAnchorPointInPoints.x;
|
||||
y += m_tAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Make matrix
|
||||
CCFloat c = m_pBody->rot.x;
|
||||
CCFloat s = m_pBody->rot.y;
|
||||
|
||||
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){
|
||||
x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y;
|
||||
y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y;
|
||||
}
|
||||
|
||||
// Rot, Translate Matrix
|
||||
m_tTransform = CCAffineTransformMake( c, s,
|
||||
-s, c,
|
||||
x, y );
|
||||
|
||||
return m_tTransform;
|
||||
}
|
||||
|
||||
HelloWorld::HelloWorld()
|
||||
|
@ -41,149 +81,191 @@ HelloWorld::HelloWorld()
|
|||
|
||||
HelloWorld::~HelloWorld()
|
||||
{
|
||||
// manually Free rogue shapes
|
||||
for( int i=0;i<4;i++) {
|
||||
cpShapeFree( m_pWalls[i] );
|
||||
}
|
||||
|
||||
cpSpaceFree( m_pSpace );
|
||||
|
||||
}
|
||||
|
||||
CCScene* HelloWorld::scene()
|
||||
{
|
||||
// 'scene' is an autorelease object.
|
||||
CCScene *scene = CCScene::node();
|
||||
// 'scene' is an autorelease object.
|
||||
CCScene *scene = CCScene::node();
|
||||
|
||||
// 'layer' is an autorelease object.
|
||||
HelloWorld *layer = HelloWorld::node();
|
||||
// 'layer' is an autorelease object.
|
||||
HelloWorld *layer = HelloWorld::node();
|
||||
|
||||
// add layer as a child to scene
|
||||
scene->addChild(layer);
|
||||
// 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);
|
||||
// return the scene
|
||||
return scene;
|
||||
}
|
||||
|
||||
bool HelloWorld::init()
|
||||
{
|
||||
bool ret = false;
|
||||
if (!CCLayer::init())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ret = CCLayer::init())
|
||||
{
|
||||
setIsTouchEnabled(true);
|
||||
// enable events
|
||||
setIsTouchEnabled(true);
|
||||
setIsAccelerometerEnabled(true);
|
||||
|
||||
CCSize wins = CCDirector::sharedDirector()->getWinSize();
|
||||
cpInitChipmunk();
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
|
||||
space = cpSpaceNew();
|
||||
cpSpaceResizeStaticHash(space, 400.0f, 40);
|
||||
cpSpaceResizeActiveHash(space, 100, 600);
|
||||
// title
|
||||
CCLabelTTF *label = CCLabelTTF::labelWithString("Multi touch the screen", "Marker Felt", 36);
|
||||
label->setPosition(ccp( s.width / 2, s.height - 30));
|
||||
this->addChild(label, -1);
|
||||
|
||||
space->gravity = cpv(0, 0);
|
||||
space->elasticIterations = space->iterations;
|
||||
// init physics
|
||||
initPhysics();
|
||||
|
||||
cpShape *shape;
|
||||
#if 1
|
||||
// Use batch node. Faster
|
||||
CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("grossini_dance_atlas.png", 100);
|
||||
m_pSpriteTexture = parent->getTexture();
|
||||
#else
|
||||
// doesn't use batch node. Slower
|
||||
m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("grossini_dance_atlas.png");
|
||||
CCNode *parent = CCNode::node();
|
||||
#endif
|
||||
addChild(parent, 0, kTagParentNode);
|
||||
|
||||
// bottom
|
||||
shape = cpSegmentShapeNew(staticBody, cpv(0,0), cpv(wins.width,0), 0.0f);
|
||||
shape->e = 1.0f; shape->u = 1.0f;
|
||||
cpSpaceAddStaticShape(space, shape);
|
||||
addNewSpriteAtPosition(ccp(200,200));
|
||||
|
||||
// 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);
|
||||
scheduleUpdate();
|
||||
|
||||
// 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;
|
||||
return true;
|
||||
}
|
||||
|
||||
void HelloWorld::onEnter()
|
||||
|
||||
void HelloWorld::initPhysics()
|
||||
{
|
||||
CCLayer::onEnter();
|
||||
CCSize s = CCDirector::sharedDirector()->getWinSize();
|
||||
|
||||
// init chipmunk
|
||||
cpInitChipmunk();
|
||||
|
||||
m_pSpace = cpSpaceNew();
|
||||
|
||||
m_pSpace->gravity = cpv(0, -100);
|
||||
|
||||
//
|
||||
// rogue shapes
|
||||
// We have to free them manually
|
||||
//
|
||||
// bottom
|
||||
m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(s.width,0), 0.0f);
|
||||
|
||||
// top
|
||||
m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
// left
|
||||
m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(0,s.height), 0.0f);
|
||||
|
||||
// right
|
||||
m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
for( int i=0;i<4;i++) {
|
||||
m_pWalls[i]->e = 1.0f;
|
||||
m_pWalls[i]->u = 1.0f;
|
||||
cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] );
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::step(ccTime delta)
|
||||
void HelloWorld::update(ccTime delta)
|
||||
{
|
||||
int steps = 2;
|
||||
CGFloat dt = delta/(CGFloat)steps;
|
||||
// Should use a fixed size step based on the animation interval.
|
||||
int steps = 2;
|
||||
CCFloat dt = CCDirector::sharedDirector()->getAnimationInterval()/(CCFloat)steps;
|
||||
|
||||
for(int i=0; i<steps; i++)
|
||||
{
|
||||
cpSpaceStep(space, dt);
|
||||
}
|
||||
cpSpaceHashEach(space->activeShapes, &eachShape, NULL);
|
||||
cpSpaceHashEach(space->staticShapes, &eachShape, NULL);
|
||||
for(int i=0; i<steps; i++){
|
||||
cpSpaceStep(m_pSpace, dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void HelloWorld::ccTouchesEnded(CCSet *touches, CCEvent *event)
|
||||
void HelloWorld::addNewSpriteAtPosition(CCPoint pos)
|
||||
{
|
||||
CCSetIterator it;
|
||||
CCTouch *touch;
|
||||
int posx, posy;
|
||||
|
||||
for (it = touches->begin(); it != touches->end(); it++) {
|
||||
touch = (CCTouch*)(*it);
|
||||
CCNode *parent = getChildByTag(kTagParentNode);
|
||||
|
||||
if (! touch) {
|
||||
break;
|
||||
}
|
||||
posx = CCRANDOM_0_1() * 200.0f;
|
||||
posy = CCRANDOM_0_1() * 200.0f;
|
||||
|
||||
CCPoint location = touch->locationInView(touch->view());
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
addNewSpriteX(location.x, location.y);
|
||||
}
|
||||
posx = (posx % 4) * 85;
|
||||
posy = (posy % 3) * 121;
|
||||
|
||||
ChipmunkPhysicsSprite *sprite = new ChipmunkPhysicsSprite();
|
||||
sprite->initWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121));
|
||||
sprite->autorelease();
|
||||
|
||||
parent->addChild(sprite);
|
||||
|
||||
sprite->setPosition(pos);
|
||||
|
||||
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, cpvzero));
|
||||
|
||||
body->p = cpv(pos.x, pos.y);
|
||||
cpSpaceAddBody(m_pSpace, body);
|
||||
|
||||
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
|
||||
shape->e = 0.5f; shape->u = 0.5f;
|
||||
cpSpaceAddShape(m_pSpace, shape);
|
||||
|
||||
sprite->setPhysicsBody(body);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
location = CCDirector::sharedDirector()->convertToGL(location);
|
||||
|
||||
addNewSpriteAtPosition( location );
|
||||
}
|
||||
}
|
||||
|
||||
void HelloWorld::didAccelerate(CCAcceleration* pAccelerationValue)
|
||||
{
|
||||
static float prevX=0, prevY=0;
|
||||
|
||||
#define kFilterFactor 0.05f
|
||||
|
||||
float accelX = (float) pAccelerationValue->x * kFilterFactor + (1- kFilterFactor)*prevX;
|
||||
float accelY = (float) pAccelerationValue->y * kFilterFactor + (1- kFilterFactor)*prevY;
|
||||
|
||||
prevX = accelX;
|
||||
prevY = accelY;
|
||||
|
||||
CCPoint v = ccp( accelX, accelY);
|
||||
v = ccpMult(v, 200);
|
||||
m_pSpace->gravity = cpv(v.x, v.y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -14,23 +14,38 @@
|
|||
// include Chipmunk headers
|
||||
#include "chipmunk.h"
|
||||
|
||||
class ChipmunkPhysicsSprite : public cocos2d::CCSprite
|
||||
{
|
||||
public:
|
||||
ChipmunkPhysicsSprite();
|
||||
virtual ~ChipmunkPhysicsSprite();
|
||||
void setPhysicsBody(cpBody* body);
|
||||
virtual bool isDirty(void);
|
||||
virtual cocos2d::CCAffineTransform nodeToParentTransform(void);
|
||||
private:
|
||||
cpBody* m_pBody; // strong ref
|
||||
};
|
||||
|
||||
// HelloWorld Layer
|
||||
class HelloWorld : public cocos2d::CCLayer {
|
||||
public:
|
||||
HelloWorld();
|
||||
~HelloWorld();
|
||||
HelloWorld();
|
||||
~HelloWorld();
|
||||
bool init();
|
||||
static cocos2d::CCScene* scene();
|
||||
LAYER_NODE_FUNC(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);
|
||||
void initPhysics();
|
||||
void addNewSpriteAtPosition(cocos2d::CCPoint p);
|
||||
void update(cocos2d::ccTime dt);
|
||||
virtual void ccTouchesEnded(cocos2d::CCSet* touches, cocos2d::CCEvent* event);
|
||||
virtual void didAccelerate(cocos2d::CCAcceleration* pAccelerationValue);
|
||||
|
||||
private:
|
||||
bool init();
|
||||
cpSpace *space;
|
||||
cocos2d::CCTexture2D* m_pSpriteTexture; // weak ref
|
||||
cpSpace* m_pSpace; // strong ref
|
||||
cpShape* m_pWalls[4];
|
||||
|
||||
};
|
||||
|
||||
#endif // __HELLOW_WORLD_H__
|
||||
|
|
|
@ -29,7 +29,7 @@ static AppDelegate s_sharedApplication;
|
|||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#endif
|
||||
|
||||
USING_NS_CC;
|
||||
using namespace std;
|
||||
using namespace CocosDenshion;
|
||||
|
||||
AppDelegate::AppDelegate()
|
||||
|
@ -63,10 +64,6 @@ bool AppDelegate::initInstance()
|
|||
|
||||
#endif // CC_PLATFORM_ANDROID
|
||||
|
||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
|
||||
// MaxAksenov said it's NOT a very elegant solution. I agree, haha
|
||||
CCDirector::sharedDirector()->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
#endif
|
||||
bRet = true;
|
||||
} while (0);
|
||||
return bRet;
|
||||
|
@ -82,7 +79,7 @@ bool AppDelegate::applicationDidFinishLaunching()
|
|||
// pDirector->enableRetinaDisplay(true);
|
||||
|
||||
// turn on display FPS
|
||||
pDirector->setDisplayFPS(true);
|
||||
pDirector->setDisplayStats(true);
|
||||
|
||||
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
|
||||
|
||||
|
|
|
@ -30,12 +30,13 @@ local function creatDog()
|
|||
spriteDog.isPaused = false
|
||||
spriteDog:setPosition(0, winSize.height / 4 * 3)
|
||||
|
||||
local animFrames = CCMutableArray_CCSpriteFrame__:new(2)
|
||||
local animFrames = CCArray:arrayWithCapacity(2)
|
||||
|
||||
animFrames:addObject(frame0)
|
||||
animFrames:addObject(frame1)
|
||||
|
||||
local animation = CCAnimation:animationWithFrames(animFrames, 0.5)
|
||||
local animate = CCAnimate:actionWithAnimation(animation, false);
|
||||
local animation = CCAnimation:animationWithSpriteFrames(animFrames, 0.5)
|
||||
local animate = CCAnimate:actionWithAnimation(animation);
|
||||
spriteDog:runAction(CCRepeatForever:actionWithAction(animate))
|
||||
|
||||
-- moving dog at every frame
|
||||
|
@ -47,10 +48,11 @@ local function creatDog()
|
|||
else
|
||||
x = x + 1
|
||||
end
|
||||
|
||||
spriteDog:setPositionX(x)
|
||||
end
|
||||
|
||||
CCScheduler:sharedScheduler():scheduleScriptFunc(tick, 0, false)
|
||||
CCDirector:sharedDirector():getScheduler():scheduleScriptFunc(tick, 0, false)
|
||||
|
||||
return spriteDog
|
||||
end
|
||||
|
@ -110,7 +112,7 @@ local function createLayerFram()
|
|||
end
|
||||
|
||||
local function onTouchEnded(x, y)
|
||||
cclog("onTouchEnded")
|
||||
cclog("onTouchEnded: %0.2f, %0.2f", x, y)
|
||||
touchBeginPoint = nil
|
||||
spriteDog.isPaused = false
|
||||
end
|
||||
|
@ -151,7 +153,7 @@ local function createLayerMenu()
|
|||
end
|
||||
|
||||
-- add a popup menu
|
||||
local menuPopupItem = CCMenuItemImage:itemFromNormalImage("menu2.png", "menu2.png")
|
||||
local menuPopupItem = CCMenuItemImage:itemWithNormalImage("menu2.png", "menu2.png")
|
||||
menuPopupItem:setPosition(0, 0)
|
||||
menuPopupItem:registerScriptHandler(menuCallbackClosePopup)
|
||||
menuPopup = CCMenu:menuWithItem(menuPopupItem)
|
||||
|
@ -160,7 +162,7 @@ local function createLayerMenu()
|
|||
layerMenu:addChild(menuPopup)
|
||||
|
||||
-- add the left-bottom "tools" menu to invoke menuPopup
|
||||
local menuToolsItem = CCMenuItemImage:itemFromNormalImage("menu1.png", "menu1.png")
|
||||
local menuToolsItem = CCMenuItemImage:itemWithNormalImage("menu1.png", "menu1.png")
|
||||
menuToolsItem:setPosition(0, 0)
|
||||
menuToolsItem:registerScriptHandler(menuCallbackOpenPopup)
|
||||
menuTools = CCMenu:menuWithItem(menuToolsItem)
|
||||
|
|
|
@ -45,7 +45,7 @@ static AppDelegate s_sharedApplication;
|
|||
window = [[UIWindow alloc] initWithFrame: [[UIScreen mainScreen] bounds]];
|
||||
EAGLView *__glView = [EAGLView viewWithFrame: [window bounds]
|
||||
pixelFormat: kEAGLColorFormatRGBA8
|
||||
depthFormat: GL_DEPTH_COMPONENT16_OES
|
||||
depthFormat: GL_DEPTH_COMPONENT16
|
||||
preserveBackbuffer: NO
|
||||
sharegroup: nil
|
||||
multiSampling: NO
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
a0108c887c7176801731f3e9503263b79a9eeb62
|
|
@ -9,6 +9,7 @@
|
|||
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG,LOG_TAG,__VA_ARGS__)
|
||||
|
||||
using namespace cocos2d;
|
||||
using namespace cocos2d::extension;
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -22,16 +23,16 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved)
|
|||
|
||||
void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thiz, jint w, jint h)
|
||||
{
|
||||
if (!cocos2d::CCDirector::sharedDirector()->getOpenGLView())
|
||||
if (!CCDirector::sharedDirector()->getOpenGLView())
|
||||
{
|
||||
cocos2d::CCEGLView *view = &cocos2d::CCEGLView::sharedOpenGLView();
|
||||
CCEGLView *view = &CCEGLView::sharedOpenGLView();
|
||||
view->setFrameSize(w, h);
|
||||
// if you want to run in WVGA with HVGA resource, set it
|
||||
// view->setDesignResolutionSize(480, 320);
|
||||
cocos2d::CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
CCDirector::sharedDirector()->setOpenGLView(view);
|
||||
|
||||
AppDelegate *pAppDelegate = new AppDelegate();
|
||||
cocos2d::CCApplication::sharedApplication().run();
|
||||
CCApplication::sharedApplication().run();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -39,9 +40,9 @@ void Java_org_cocos2dx_lib_Cocos2dxRenderer_nativeInit(JNIEnv* env, jobject thi
|
|||
ccGLInvalidateStateCache();
|
||||
|
||||
CCShaderCache::sharedShaderCache()->reloadDefaultShaders();
|
||||
cocos2d::CCTextureCache::reloadAllTextures();
|
||||
cocos2d::CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
cocos2d::CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
CCTextureCache::reloadAllTextures();
|
||||
CCNotificationCenter::sharedNotificationCenter()->postNotification(EVNET_COME_TO_FOREGROUND, NULL);
|
||||
CCDirector::sharedDirector()->setGLDefaultValues();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
0ffd9a2963117b5a53222965ff2d95f8178971f2
|
||||
d1a839f74c0ea5ee4cc2a177a02afb14a4897067
|
|
@ -17,20 +17,20 @@ void removeShape( cpBody *body, cpShape *shape, void *data )
|
|||
}
|
||||
|
||||
ChipmunkPhysicsSprite::ChipmunkPhysicsSprite()
|
||||
: body_(NULL)
|
||||
: m_pBody(NULL)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ChipmunkPhysicsSprite::~ChipmunkPhysicsSprite()
|
||||
{
|
||||
cpBodyEachShape(body_, removeShape, NULL);
|
||||
cpBodyFree( body_ );
|
||||
cpBodyEachShape(m_pBody, removeShape, NULL);
|
||||
cpBodyFree( m_pBody );
|
||||
}
|
||||
|
||||
void ChipmunkPhysicsSprite::setPhysicsBody(cpBody * body)
|
||||
{
|
||||
body_ = body;
|
||||
m_pBody = body;
|
||||
}
|
||||
|
||||
// this method will only get called if the sprite is batched.
|
||||
|
@ -43,8 +43,8 @@ bool ChipmunkPhysicsSprite::isDirty(void)
|
|||
|
||||
CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void)
|
||||
{
|
||||
CCFloat x = body_->p.x;
|
||||
CCFloat y = body_->p.y;
|
||||
CCFloat x = m_pBody->p.x;
|
||||
CCFloat y = m_pBody->p.y;
|
||||
|
||||
if ( !getIsRelativeAnchorPoint() ) {
|
||||
x += m_tAnchorPointInPoints.x;
|
||||
|
@ -52,8 +52,8 @@ CCAffineTransform ChipmunkPhysicsSprite::nodeToParentTransform(void)
|
|||
}
|
||||
|
||||
// Make matrix
|
||||
CCFloat c = body_->rot.x;
|
||||
CCFloat s = body_->rot.y;
|
||||
CCFloat c = m_pBody->rot.x;
|
||||
CCFloat s = m_pBody->rot.y;
|
||||
|
||||
if( ! CCPoint::CCPointEqualToPoint(m_tAnchorPointInPoints, CCPointZero) ){
|
||||
x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y;
|
||||
|
@ -90,10 +90,10 @@ ChipmunkAccelTouchTestLayer::ChipmunkAccelTouchTestLayer()
|
|||
#if 1
|
||||
// Use batch node. Faster
|
||||
CCSpriteBatchNode *parent = CCSpriteBatchNode::batchNodeWithFile("Images/grossini_dance_atlas.png", 100);
|
||||
spriteTexture_ = parent->getTexture();
|
||||
m_pSpriteTexture = parent->getTexture();
|
||||
#else
|
||||
// doesn't use batch node. Slower
|
||||
spriteTexture_ = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png");
|
||||
m_pSpriteTexture = CCTextureCache::sharedTextureCache()->addImage("Images/grossini_dance_atlas.png");
|
||||
CCNode *parent = CCNode::node();
|
||||
#endif
|
||||
addChild(parent, 0, kTagParentNode);
|
||||
|
@ -107,10 +107,10 @@ ChipmunkAccelTouchTestLayer::~ChipmunkAccelTouchTestLayer()
|
|||
{
|
||||
// manually Free rogue shapes
|
||||
for( int i=0;i<4;i++) {
|
||||
cpShapeFree( walls_[i] );
|
||||
cpShapeFree( m_pWalls[i] );
|
||||
}
|
||||
|
||||
cpSpaceFree( space_ );
|
||||
cpSpaceFree( m_pSpace );
|
||||
|
||||
}
|
||||
|
||||
|
@ -121,30 +121,30 @@ void ChipmunkAccelTouchTestLayer::initPhysics()
|
|||
// init chipmunk
|
||||
cpInitChipmunk();
|
||||
|
||||
space_ = cpSpaceNew();
|
||||
m_pSpace = cpSpaceNew();
|
||||
|
||||
space_->gravity = cpv(0, -100);
|
||||
m_pSpace->gravity = cpv(0, -100);
|
||||
|
||||
//
|
||||
// rogue shapes
|
||||
// We have to free them manually
|
||||
//
|
||||
// bottom
|
||||
walls_[0] = cpSegmentShapeNew( space_->staticBody, cpv(0,0), cpv(s.width,0), 0.0f);
|
||||
m_pWalls[0] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(s.width,0), 0.0f);
|
||||
|
||||
// top
|
||||
walls_[1] = cpSegmentShapeNew( space_->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f);
|
||||
m_pWalls[1] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,s.height), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
// left
|
||||
walls_[2] = cpSegmentShapeNew( space_->staticBody, cpv(0,0), cpv(0,s.height), 0.0f);
|
||||
m_pWalls[2] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(0,0), cpv(0,s.height), 0.0f);
|
||||
|
||||
// right
|
||||
walls_[3] = cpSegmentShapeNew( space_->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
|
||||
m_pWalls[3] = cpSegmentShapeNew( m_pSpace->staticBody, cpv(s.width,0), cpv(s.width,s.height), 0.0f);
|
||||
|
||||
for( int i=0;i<4;i++) {
|
||||
walls_[i]->e = 1.0f;
|
||||
walls_[i]->u = 1.0f;
|
||||
cpSpaceAddStaticShape(space_, walls_[i] );
|
||||
m_pWalls[i]->e = 1.0f;
|
||||
m_pWalls[i]->u = 1.0f;
|
||||
cpSpaceAddStaticShape(m_pSpace, m_pWalls[i] );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ void ChipmunkAccelTouchTestLayer::update(ccTime delta)
|
|||
CCFloat dt = CCDirector::sharedDirector()->getAnimationInterval()/(CCFloat)steps;
|
||||
|
||||
for(int i=0; i<steps; i++){
|
||||
cpSpaceStep(space_, dt);
|
||||
cpSpaceStep(m_pSpace, dt);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ void ChipmunkAccelTouchTestLayer::addNewSpriteAtPosition(CCPoint pos)
|
|||
posy = (posy % 3) * 121;
|
||||
|
||||
ChipmunkPhysicsSprite *sprite = new ChipmunkPhysicsSprite();
|
||||
sprite->initWithTexture(spriteTexture_, CCRectMake(posx, posy, 85, 121));
|
||||
sprite->initWithTexture(m_pSpriteTexture, CCRectMake(posx, posy, 85, 121));
|
||||
sprite->autorelease();
|
||||
|
||||
parent->addChild(sprite);
|
||||
|
@ -212,11 +212,11 @@ void ChipmunkAccelTouchTestLayer::addNewSpriteAtPosition(CCPoint pos)
|
|||
cpBody *body = cpBodyNew(1.0f, cpMomentForPoly(1.0f, num, verts, cpvzero));
|
||||
|
||||
body->p = cpv(pos.x, pos.y);
|
||||
cpSpaceAddBody(space_, body);
|
||||
cpSpaceAddBody(m_pSpace, body);
|
||||
|
||||
cpShape* shape = cpPolyShapeNew(body, num, verts, cpvzero);
|
||||
shape->e = 0.5f; shape->u = 0.5f;
|
||||
cpSpaceAddShape(space_, shape);
|
||||
cpSpaceAddShape(m_pSpace, shape);
|
||||
|
||||
sprite->setPhysicsBody(body);
|
||||
}
|
||||
|
@ -261,7 +261,7 @@ void ChipmunkAccelTouchTestLayer::didAccelerate(CCAcceleration* pAccelerationVal
|
|||
|
||||
CCPoint v = ccp( accelX, accelY);
|
||||
v = ccpMult(v, 200);
|
||||
space_->gravity = cpv(v.x, v.y);
|
||||
m_pSpace->gravity = cpv(v.x, v.y);
|
||||
}
|
||||
|
||||
void ChipmunkAccelTouchTestScene::runThisTest()
|
||||
|
|
|
@ -22,11 +22,11 @@ public:
|
|||
void update(ccTime dt);
|
||||
virtual void ccTouchesEnded(CCSet* touches, CCEvent* event);
|
||||
virtual void didAccelerate(CCAcceleration* pAccelerationValue);
|
||||
CCTexture2D *spriteTexture_; // weak ref
|
||||
|
||||
cpSpace *space_; // strong ref
|
||||
|
||||
cpShape *walls_[4];
|
||||
private:
|
||||
CCTexture2D* m_pSpriteTexture; // weak ref
|
||||
cpSpace* m_pSpace; // strong ref
|
||||
cpShape* m_pWalls[4];
|
||||
};
|
||||
|
||||
class ChipmunkPhysicsSprite : public CCSprite
|
||||
|
@ -38,7 +38,7 @@ public:
|
|||
virtual bool isDirty(void);
|
||||
virtual CCAffineTransform nodeToParentTransform(void);
|
||||
private:
|
||||
cpBody *body_; // strong ref
|
||||
cpBody* m_pBody; // strong ref
|
||||
};
|
||||
|
||||
class ChipmunkAccelTouchTestScene : public TestScene
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include "cocos2dExt.h"
|
||||
|
||||
USING_NS_CC;
|
||||
|
||||
USING_NS_CC_EXT;
|
||||
|
||||
#define CONTROL_SCENE_NODE_FUNC(controlScene) \
|
||||
public: \
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
enum
|
||||
{
|
||||
MAX_COUNT = 2,
|
||||
MAX_COUNT = 3,
|
||||
LINE_SPACE = 40,
|
||||
kItemTagBasic = 1000,
|
||||
};
|
||||
|
@ -13,7 +13,8 @@ enum
|
|||
static const std::string testsName[MAX_COUNT] =
|
||||
{
|
||||
"NotificationCenterTest",
|
||||
"CCControlButtonTest"
|
||||
"CCControlButtonTest",
|
||||
"TextureWatcherTest"
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
|
@ -59,6 +60,13 @@ void ExtensionsMainLayer::menuCallback(CCObject* pSender)
|
|||
CCDirector::sharedDirector()->replaceScene(pScene);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
{
|
||||
static bool s_bOpened = false;
|
||||
s_bOpened = !s_bOpened;
|
||||
CCTextureWatcher::sharedTextureWatcher()->setDisplayWatcher(s_bOpened);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
#include "../testBasic.h"
|
||||
//#import "cocos2d.h"
|
||||
|
||||
|
||||
class SchedulerTestLayer : public CCLayer
|
||||
|
|
|
@ -166,6 +166,7 @@ TestController::TestController()
|
|||
setIsTouchEnabled(true);
|
||||
|
||||
addChild(pMenu, 1);
|
||||
|
||||
}
|
||||
|
||||
TestController::~TestController()
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
#include "cocos2d.h"
|
||||
|
||||
using namespace cocos2d;
|
||||
USING_NS_CC;
|
||||
USING_NS_CC_EXT;
|
||||
using namespace std;
|
||||
|
||||
class TestScene : public CCScene
|
||||
|
|
|
@ -2,7 +2,7 @@ pushd ../../
|
|||
|
||||
echo "generating libcocos2dx"
|
||||
mkdir -p template/xcode4/lib_cocos2dx.xctemplate
|
||||
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 airplay wophone bada third_party CCImage.cpp CCThread.cpp CCFileUtils.cpp Android.mk Linux linux qnx marmalade" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
|
||||
python ./tools/xcode4_template_generator/template_generator.py --directory cocos2dx --identifier libcocos2dx --prefix libs --exclude "android win32 airplay wophone bada third_party CCImage.cpp CCThread.cpp proj.ios CCFileUtilsCommon_cpp.h CCImageCommon_cpp.h CCFileUtils.cpp Android.mk Linux linux qnx marmalade" > ./template/xcode4/lib_cocos2dx.xctemplate/TemplateInfo.plist
|
||||
|
||||
echo "generating libcocosdenshion"
|
||||
mkdir -p template/xcode4/lib_cocosdenshion.xctemplate
|
||||
|
|
Loading…
Reference in New Issue