Merge pull request #792 from dumganhar/gles20

issue #1056: Moved some singletons to CCDirector. It is more easily managed by CCDirector.
This commit is contained in:
James Chen 2012-03-21 02:40:04 -07:00
commit ad96cd86e0
36 changed files with 148 additions and 195 deletions

View File

@ -44,6 +44,7 @@ THE SOFTWARE.
#include "CCLabelTTF.h"
#include "CCConfiguration.h"
#include "CCKeypadDispatcher.h"
#include "CCAccelerometer.h"
#include "CCGL.h"
#include "CCAnimationCache.h"
#include "CCTouch.h"
@ -85,6 +86,11 @@ CCDirector* CCDirector::sharedDirector(void)
return &s_sharedDirector;
}
CCDirector::CCDirector(void)
{
}
bool CCDirector::init(void)
{
CCLOG("cocos2d: %s", cocos2dVersion());
@ -133,6 +139,15 @@ bool CCDirector::init(void)
// action manager
m_pActionManager = new CCActionManager();
m_pScheduler->scheduleUpdateForTarget(m_pActionManager, kCCActionManagerPriority, false);
// touchDispatcher
m_pTouchDispatcher = new CCTouchDispatcher();
m_pTouchDispatcher->init();
// KeypadDispatcher
m_pKeypadDispatcher = new CCKeypadDispatcher();
// Accelerometer
m_pAccelerometer = new CCAccelerometer();
// create autorelease pool
CCPoolManager::getInstance()->push();
@ -153,15 +168,14 @@ CCDirector::~CCDirector(void)
CC_SAFE_RELEASE(m_pobScenesStack);
CC_SAFE_RELEASE(m_pScheduler);
CC_SAFE_RELEASE(m_pActionManager);
CC_SAFE_RELEASE(m_pTouchDispatcher);
CC_SAFE_RELEASE(m_pKeypadDispatcher);
CC_SAFE_DELETE(m_pAccelerometer);
// pop the autorelease pool
CCPoolManager::getInstance()->pop();
// delete m_pLastUpdate
CC_SAFE_DELETE(m_pLastUpdate);
CCKeypadDispatcher::purgeSharedDispatcher();
// delete fps string
delete []m_pszFPS;
}
@ -300,9 +314,8 @@ void CCDirector::setOpenGLView(CC_GLVIEW *pobOpenGLView)
updateContentScaleFactor();
}
CCTouchDispatcher *pTouchDispatcher = CCTouchDispatcher::sharedDispatcher();
m_pobOpenGLView->setTouchDelegate(pTouchDispatcher);
pTouchDispatcher->setDispatchEvents(true);
m_pobOpenGLView->setTouchDelegate(m_pTouchDispatcher);
m_pTouchDispatcher->setDispatchEvents(true);
}
}
@ -577,7 +590,7 @@ void CCDirector::resetDirector()
{
// don't release the event handlers
// They are needed in case the director is run again
CCTouchDispatcher::sharedDispatcher()->removeAllDelegates();
m_pTouchDispatcher->removeAllDelegates();
if (m_pRunningScene)
{
@ -613,7 +626,7 @@ void CCDirector::purgeDirector()
{
// don't release the event handlers
// They are needed in case the director is run again
CCTouchDispatcher::sharedDispatcher()->removeAllDelegates();
m_pTouchDispatcher->removeAllDelegates();
if (m_pRunningScene)
{
@ -927,6 +940,44 @@ CCActionManager* CCDirector::getActionManager()
return m_pActionManager;
}
void CCDirector::setTouchDispatcher(CCTouchDispatcher* pTouchDispatcher)
{
CC_SAFE_RETAIN(pTouchDispatcher);
CC_SAFE_RELEASE(m_pTouchDispatcher);
m_pTouchDispatcher = pTouchDispatcher;
}
CCTouchDispatcher* CCDirector::getTouchDispatcher()
{
return m_pTouchDispatcher;
}
void CCDirector::setKeypadDispatcher(CCKeypadDispatcher* pKeypadDispatcher)
{
CC_SAFE_RETAIN(pKeypadDispatcher);
CC_SAFE_RELEASE(m_pKeypadDispatcher);
m_pKeypadDispatcher = pKeypadDispatcher;
}
CCKeypadDispatcher* CCDirector::getKeypadDispatcher()
{
return m_pKeypadDispatcher;
}
void CCDirector::setAccelerometer(CCAccelerometer* pAccelerometer)
{
if (m_pAccelerometer != pAccelerometer)
{
CC_SAFE_DELETE(m_pAccelerometer);
m_pAccelerometer = pAccelerometer;
}
}
CCAccelerometer* CCDirector::getAccelerometer()
{
return m_pAccelerometer;
}
/***************************************************
* implementation of DisplayLinkDirector
**************************************************/

View File

@ -142,6 +142,10 @@ class CCDirectorDelegate;
class CCNode;
class CCScheduler;
class CCActionManager;
class CCTouchDispatcher;
class CCKeypadDispatcher;
class CCAccelerometer;
/**
@brief Class that creates and handle the main Window and manages how
and when to execute the Scenes.
@ -164,10 +168,10 @@ and when to execute the Scenes.
*/
class CC_DLL CCDirector : public CCObject
{
public:
virtual bool init(void);
public:
CCDirector(void);
virtual ~CCDirector(void);
CCDirector(void) {}
virtual bool init(void);
// attribute
@ -393,6 +397,21 @@ public:
*/
CC_PROPERTY(CCActionManager*, m_pActionManager, ActionManager);
/** CCTouchDispatcher associated with this director
@since v2.0
*/
CC_PROPERTY(CCTouchDispatcher*, m_pTouchDispatcher, TouchDispatcher);
/** CCKeypadDispatcher associated with this director
@since v2.0
*/
CC_PROPERTY(CCKeypadDispatcher*, m_pKeypadDispatcher, KeypadDispatcher);
/** CCAccelerometer associated with this director
@since v2.0
*/
CC_PROPERTY(CCAccelerometer*, m_pAccelerometer, Accelerometer);
/** returns a shared instance of the director */
static CCDirector* sharedDirector(void);
void resetDirector();

View File

@ -47,16 +47,6 @@ public:
CCKeypadDispatcher();
~CCKeypadDispatcher();
/**
@brief Returns the shared CCKeypadDispatcher object for the system.
*/
static CCKeypadDispatcher* sharedDispatcher();
/**
@brief Release the shared CCKeypadDispatcher object from the system.
*/
static void purgeSharedDispatcher();
/**
@brief add delegate to concern keypad msg
*/

View File

@ -140,10 +140,7 @@ public:
virtual void touchesCancelled(CCSet* touches, CCEvent* pEvent);
public:
/** singleton of the CCTouchDispatcher */
static CCTouchDispatcher* sharedDispatcher();
CCTouchHandler* findHandler(CCTouchDelegate *pDelegate);
protected:
void forceRemoveDelegate(CCTouchDelegate *pDelegate);
void forceAddHandler(CCTouchHandler *pHandler, CCArray* pArray);

View File

@ -27,7 +27,6 @@ THE SOFTWARE.
namespace cocos2d {
static CCKeypadDispatcher* s_KeypadDispatcher = NULL;
//------------------------------------------------------------------
//
// CCKeypadDispatcher
@ -59,25 +58,6 @@ CCKeypadDispatcher::~CCKeypadDispatcher()
}
}
CCKeypadDispatcher* CCKeypadDispatcher::sharedDispatcher()
{
if (! s_KeypadDispatcher)
{
s_KeypadDispatcher = new CCKeypadDispatcher;
}
return s_KeypadDispatcher;
}
void CCKeypadDispatcher::purgeSharedDispatcher()
{
if (s_KeypadDispatcher)
{
s_KeypadDispatcher->release();
s_KeypadDispatcher = NULL;
}
}
void CCKeypadDispatcher::removeDelegate(CCKeypadDelegate* pDelegate)
{
if (!pDelegate)

View File

@ -92,23 +92,24 @@ CCLayer *CCLayer::node()
void CCLayer::registerWithTouchDispatcher()
{
CCDirector* pDirector = CCDirector::sharedDirector();
if (m_pScriptHandlerEntry)
{
if (m_pScriptHandlerEntry->getIsMultiTouches())
{
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0);
pDirector->getTouchDispatcher()->addStandardDelegate(this, 0);
LUALOG("[LUA] Add multi-touches event handler: %d", m_pScriptHandlerEntry->getHandler());
}
else
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this,
pDirector->getTouchDispatcher()->addTargetedDelegate(this,
m_pScriptHandlerEntry->getPriority(),
m_pScriptHandlerEntry->getSwallowsTouches());
LUALOG("[LUA] Add touch event handler: %d", m_pScriptHandlerEntry->getHandler());
}
return;
}
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this,0);
pDirector->getTouchDispatcher()->addStandardDelegate(this,0);
}
void CCLayer::registerScriptTouchHandler(int nHandler, bool bIsMultiTouches, int nPriority, bool bSwallowsTouches)
@ -157,7 +158,8 @@ void CCLayer::setIsTouchEnabled(bool enabled)
else
{
// have problems?
CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
}
}
}
@ -177,13 +179,14 @@ void CCLayer::setIsAccelerometerEnabled(bool enabled)
if (m_bIsRunning)
{
CCDirector* pDirector = CCDirector::sharedDirector();
if (enabled)
{
CCAccelerometer::sharedAccelerometer()->setDelegate(this);
pDirector->getAccelerometer()->setDelegate(this);
}
else
{
CCAccelerometer::sharedAccelerometer()->setDelegate(NULL);
pDirector->getAccelerometer()->setDelegate(NULL);
}
}
}
@ -203,13 +206,14 @@ void CCLayer::setIsKeypadEnabled(bool enabled)
if (m_bIsRunning)
{
CCDirector* pDirector = CCDirector::sharedDirector();
if (enabled)
{
CCKeypadDispatcher::sharedDispatcher()->addDelegate(this);
pDirector->getKeypadDispatcher()->addDelegate(this);
}
else
{
CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this);
pDirector->getKeypadDispatcher()->removeDelegate(this);
}
}
}
@ -218,6 +222,7 @@ void CCLayer::setIsKeypadEnabled(bool enabled)
/// Callbacks
void CCLayer::onEnter()
{
CCDirector* pDirector = CCDirector::sharedDirector();
// register 'parent' nodes first
// since events are propagated in reverse order
if (m_bIsTouchEnabled)
@ -231,34 +236,35 @@ void CCLayer::onEnter()
// add this layer to concern the Accelerometer Sensor
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->setDelegate(this);
pDirector->getAccelerometer()->setDelegate(this);
}
// add this layer to concern the kaypad msg
if (m_bIsKeypadEnabled)
{
CCKeypadDispatcher::sharedDispatcher()->addDelegate(this);
pDirector->getKeypadDispatcher()->addDelegate(this);
}
}
void CCLayer::onExit()
{
CCDirector* pDirector = CCDirector::sharedDirector();
if( m_bIsTouchEnabled )
{
CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
pDirector->getTouchDispatcher()->removeDelegate(this);
unregisterScriptTouchHandler();
}
// remove this layer from the delegates who concern Accelerometer Sensor
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->setDelegate(NULL);
pDirector->getAccelerometer()->setDelegate(NULL);
}
// remove this layer from the delegates who concern the kaypad msg
if (m_bIsKeypadEnabled)
{
CCKeypadDispatcher::sharedDispatcher()->removeDelegate(this);
pDirector->getKeypadDispatcher()->removeDelegate(this);
}
CCNode::onExit();
@ -268,7 +274,8 @@ void CCLayer::onEnterTransitionDidFinish()
{
if (m_bIsAccelerometerEnabled)
{
CCAccelerometer::sharedAccelerometer()->setDelegate(this);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getAccelerometer()->setDelegate(this);
}
CCNode::onEnterTransitionDidFinish();

View File

@ -92,7 +92,8 @@ bool CCTransitionScene::initWithDuration(ccTime t, CCScene *scene)
CCAssert( m_pInScene != m_pOutScene, "Incoming scene must be different from the outgoing scene" );
// disable events while transitions
CCTouchDispatcher::sharedDispatcher()->setDispatchEvents(false);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->setDispatchEvents(false);
this->sceneOrder();
return true;
@ -153,7 +154,7 @@ void CCTransitionScene::setNewScene(ccTime dt)
m_bIsSendCleanupToScene = director->isSendCleanupToScene();
director->replaceScene(m_pInScene);
// enable events while transitions
CCTouchDispatcher::sharedDispatcher()->setDispatchEvents(true);
director->getTouchDispatcher()->setDispatchEvents(true);
// issue #267
m_pOutScene->setIsVisible(true);
}

View File

@ -160,7 +160,8 @@ namespace cocos2d{
//Menu - Events
void CCMenu::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority, true);
}
bool CCMenu::ccTouchBegan(CCTouch* touch, CCEvent* event)

View File

@ -32,26 +32,13 @@ THE SOFTWARE.
namespace cocos2d
{
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL)
{
}
CCAccelerometer::~CCAccelerometer()
{
m_spCCAccelerometer = NULL;
}
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
if (m_spCCAccelerometer == NULL)
{
m_spCCAccelerometer = new CCAccelerometer();
}
return m_spCCAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)

View File

@ -36,13 +36,10 @@ public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
void update(float x, float y, float z, long sensorTimeStamp);
private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_obAccelerationValue;
};

View File

@ -29,7 +29,7 @@ THE SOFTWARE.
#include "JniHelper.h"
#include <android/log.h>
#include <jni.h>
#include "CCDirector.h"
#if 0
#define LOG_TAG "SensorJni"
@ -56,7 +56,8 @@ extern "C"
// (y - rcRect.origin.y) / fScreenScaleFactor,
// z,
// timeStamp);
cocos2d::CCAccelerometer::sharedAccelerometer()->update(x, y, z, timeStamp);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getAccelerometer()->update(x, y, z, timeStamp);
}
void enableAccelerometerJNI()

View File

@ -45,12 +45,6 @@ CCAccelerometer::~CCAccelerometer()
CC_SAFE_DELETE(m_pSensor);
}
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
static CCAccelerometer s_CCAccelerometer;
return &s_CCAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
{
m_pAccelDelegate = pDelegate;

View File

@ -40,7 +40,6 @@ class CC_DLL CCAccelerometer :
public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
virtual void OnDataReceived(Osp::Uix::SensorType sensorType, Osp::Uix::SensorData& sensorData , result r);

View File

@ -35,12 +35,7 @@ public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
private:
static CCAccelerometer* m_spUIAccelerometer;
};
}//namespace cocos2d

View File

@ -27,8 +27,6 @@
namespace cocos2d {
CCAccelerometer* CCAccelerometer::m_spUIAccelerometer = NULL;
CCAccelerometer::CCAccelerometer()
{
}
@ -37,15 +35,6 @@ namespace cocos2d {
{
}
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
if (m_spUIAccelerometer == NULL) {
m_spUIAccelerometer = new CCAccelerometer();
}
return m_spUIAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
{
[[AccelerometerDispatcher sharedAccelerometerDispather] addDelegate:pDelegate];

View File

@ -18,8 +18,6 @@ public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer() { return NULL; };
void removeDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
void addDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);}

View File

@ -28,29 +28,12 @@
namespace cocos2d
{
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
CCAccelerometer::CCAccelerometer() : m_pAccelDelegate(NULL)
{
}
CCAccelerometer::~CCAccelerometer()
{
if( m_spCCAccelerometer ) {
delete m_spCCAccelerometer ;
m_spCCAccelerometer = NULL;
}
}
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
if (m_spCCAccelerometer == NULL)
{
m_spCCAccelerometer = new CCAccelerometer();
}
return m_spCCAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)

View File

@ -42,16 +42,11 @@ public:
CCAccelerometer();
~CCAccelerometer();
/**
@brief Returns the shared accelerometer object for the system.
*/
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
void update(float x, float y, float z, uint64 sensorTimeStamp);
private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_obAccelerationValue;
};

View File

@ -126,7 +126,8 @@ void CCApplication::ccAccelerationUpdate()
{
// Accelerometer doesn't work on Marmalade X86 MacOS-X simulator
#if !(defined(__APPLE__) && defined(I3D_ARCH_X86))
CCAccelerometer::sharedAccelerometer()->update(s3eAccelerometerGetX(),s3eAccelerometerGetY(),s3eAccelerometerGetZ(),s3eTimerGetMs());
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getAccelerometer()->update(s3eAccelerometerGetX(),s3eAccelerometerGetY(),s3eAccelerometerGetZ(),s3eTimerGetMs());
#endif
}

View File

@ -33,7 +33,6 @@ THE SOFTWARE.
namespace cocos2d
{
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
int CCAccelerometer::m_initialOrientationAngle = 0;
CCAccelerometer::CCAccelerometer()
@ -49,14 +48,6 @@ namespace cocos2d
}
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
if (m_spCCAccelerometer == NULL)
m_spCCAccelerometer = new CCAccelerometer();
return m_spCCAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
{
m_pAccelDelegate = pDelegate;

View File

@ -37,14 +37,10 @@ public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
void update(long sensorTimeStamp);
private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_accelerationValue;
static int m_initialOrientationAngle;

View File

@ -60,8 +60,9 @@ int CCApplication::run()
{
update_time = current_time;
CCAccelerometer::sharedAccelerometer()->update(current_time);
CCDirector::sharedDirector()->mainLoop();
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getAccelerometer()->update(current_time);
pDirector->mainLoop();
}
else
{

View File

@ -109,7 +109,7 @@ namespace
void myAccelerometerKeyHook( UINT message,WPARAM wParam,LPARAM lParam )
{
cocos2d::CCAccelerometer *pAccelerometer=cocos2d::CCAccelerometer::sharedAccelerometer();
cocos2d::CCAccelerometer *pAccelerometer = cocos2d::CCDirector::sharedDirector()->getAccelerometer();
bool sendUpdate=false;
switch( message )
{
@ -148,9 +148,6 @@ namespace
namespace cocos2d
{
// static members
CCAccelerometer* CCAccelerometer::m_spCCAccelerometer = NULL;
CCAccelerometer::CCAccelerometer() :
m_pAccelDelegate(NULL)
{
@ -158,21 +155,7 @@ CCAccelerometer::CCAccelerometer() :
CCAccelerometer::~CCAccelerometer()
{
if( m_spCCAccelerometer )
{
delete m_spCCAccelerometer ;
m_spCCAccelerometer = NULL;
}
}
// static
CCAccelerometer* CCAccelerometer::sharedAccelerometer()
{
if (m_spCCAccelerometer == NULL)
{
m_spCCAccelerometer = new CCAccelerometer();
}
return m_spCCAccelerometer;
}
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)

View File

@ -35,11 +35,9 @@ public:
CCAccelerometer();
~CCAccelerometer();
static CCAccelerometer* sharedAccelerometer();
void setDelegate(CCAccelerometerDelegate* pDelegate);
void update( double x,double y,double z,double timestamp );
private:
static CCAccelerometer* m_spCCAccelerometer;
CCAccelerometerDelegate* m_pAccelDelegate;
CCAcceleration m_obAccelerationValue;
};

View File

@ -327,8 +327,9 @@ LRESULT CCEGLView::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN:
if (wParam == VK_F1 || wParam == VK_F2)
{
CCDirector* pDirector = CCDirector::sharedDirector();
if (GetKeyState(VK_LSHIFT) < 0 || GetKeyState(VK_RSHIFT) < 0 || GetKeyState(VK_SHIFT) < 0)
CCKeypadDispatcher::sharedDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
pDirector->getKeypadDispatcher()->dispatchKeypadMSG(wParam == VK_F1 ? kTypeBackClicked : kTypeMenuClicked);
}
if ( m_lpfnAccelerometerKeyHook!=NULL )
{

View File

@ -53,20 +53,6 @@ void CCTouchDispatcher::setDispatchEvents(bool bDispatchEvents)
m_bDispatchEvents = bDispatchEvents;
}
static CCTouchDispatcher *pSharedDispatcher = NULL;
CCTouchDispatcher* CCTouchDispatcher::sharedDispatcher(void)
{
// synchronized ??
if (pSharedDispatcher == NULL)
{
pSharedDispatcher = new CCTouchDispatcher();
pSharedDispatcher->init();
}
return pSharedDispatcher;
}
/*
+(id) allocWithZone:(CCZone *)zone
{

View File

@ -119,7 +119,8 @@ void MenuLayer::backCallback(CCObject* sender)
void MenuLayer::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
bool MenuLayer::ccTouchBegan(CCTouch* touch, CCEvent* event)
@ -214,7 +215,8 @@ Box2DView::~Box2DView()
void Box2DView::registerWithTouchDispatcher()
{
// higher priority than dragging
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, -10, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, -10, true);
}
bool Box2DView::ccTouchBegan(CCTouch* touch, CCEvent* event)

View File

@ -224,8 +224,6 @@ void ChipmunkAccelTouchTestLayer::addNewSpriteAtPosition(CCPoint pos)
void ChipmunkAccelTouchTestLayer::onEnter()
{
CCLayer::onEnter();
// CCAccelerometer::sharedAccelerometer()->setUpdateInterval:(1.0 / 60)];
}
void ChipmunkAccelTouchTestLayer::ccTouchesEnded(CCSet* touches, CCEvent* event)

View File

@ -161,7 +161,8 @@ void LayerTest1::onEnter()
void LayerTest1::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority + 1, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority + 1, true);
}
void LayerTest1::updateSize(CCTouch*touch)

View File

@ -111,7 +111,8 @@ MenuLayer1::MenuLayer1()
void MenuLayer1::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority+1, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, kCCMenuTouchPriority+1, true);
}
bool MenuLayer1::ccTouchBegan(CCTouch *touch, CCEvent * pEvent)
@ -148,7 +149,8 @@ void MenuLayer1::menuCallbackConfig(CCObject* sender)
void MenuLayer1::allowTouches(ccTime dt)
{
CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority+1, this);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->setPriority(kCCMenuTouchPriority+1, this);
unscheduleAllSelectors();
CCLog("TOUCHES ALLOWED AGAIN");
}
@ -156,7 +158,8 @@ void MenuLayer1::allowTouches(ccTime dt)
void MenuLayer1::menuCallbackDisabled(CCObject* sender)
{
// hijack all touch events for 5 seconds
CCTouchDispatcher::sharedDispatcher()->setPriority(kCCMenuTouchPriority-1, this);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->setPriority(kCCMenuTouchPriority-1, this);
schedule(schedule_selector(MenuLayer1::allowTouches), 5.0f);
CCLog("TOUCHES DISABLED FOR 5 SECONDS");
}

View File

@ -134,7 +134,8 @@ Parallax2::Parallax2()
void Parallax2::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
bool Parallax2::ccTouchBegan(CCTouch* touch, CCEvent* event)

View File

@ -1125,7 +1125,8 @@ std::string ParticleDemo::title()
void ParticleDemo::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
bool ParticleDemo::ccTouchBegan(CCTouch* touch, CCEvent* event)

View File

@ -99,7 +99,8 @@ std::string TouchesPerformTest1::title()
void TouchesPerformTest1::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
bool TouchesPerformTest1::ccTouchBegan(CCTouch* touch, CCEvent* event)
@ -141,7 +142,8 @@ std::string TouchesPerformTest2::title()
void TouchesPerformTest2::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addStandardDelegate(this, 0);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addStandardDelegate(this, 0);
}
void TouchesPerformTest2::ccTouchesBegan(CCSet* touches, CCEvent* event)

View File

@ -157,7 +157,8 @@ KeyboardNotificationLayer::KeyboardNotificationLayer()
void KeyboardNotificationLayer::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, false);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
}
void KeyboardNotificationLayer::keyboardWillShow(CCIMEKeyboardNotificationInfo& info)

View File

@ -1346,7 +1346,8 @@ void TileDemo::backCallback(CCObject* pSender)
void TileDemo::registerWithTouchDispatcher()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
}
bool TileDemo::ccTouchBegan(CCTouch* touch, CCEvent* event)

View File

@ -35,13 +35,15 @@ bool Paddle::initWithTexture(CCTexture2D* aTexture)
void Paddle::onEnter()
{
CCTouchDispatcher::sharedDispatcher()->addTargetedDelegate(this, 0, true);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true);
CCSprite::onEnter();
}
void Paddle::onExit()
{
CCTouchDispatcher::sharedDispatcher()->removeDelegate(this);
CCDirector* pDirector = CCDirector::sharedDirector();
pDirector->getTouchDispatcher()->removeDelegate(this);
CCSprite::onExit();
}