diff --git a/cocos2dx/cocos2dx-uphone.vcproj b/cocos2dx/cocos2dx-uphone.vcproj index 5de30a0629..6879be0cd5 100644 --- a/cocos2dx/cocos2dx-uphone.vcproj +++ b/cocos2dx/cocos2dx-uphone.vcproj @@ -488,6 +488,10 @@ RelativePath=".\include\ccTypes.h" > + + @@ -524,10 +528,6 @@ RelativePath=".\include\cocos2d.h" > - - diff --git a/cocos2dx/include/CCLayer.h b/cocos2dx/include/CCLayer.h index c6f6a293a5..44ddd1eddb 100644 --- a/cocos2dx/include/CCLayer.h +++ b/cocos2dx/include/CCLayer.h @@ -29,6 +29,7 @@ THE SOFTWARE. #include "CCNode.h" #include "CCProtocols.h" #include "CCTouchDelegateProtocol.h" +#include "CCUIAccelerometerDelegate.h" #include "ccxCommon.h" #include "CCXUIAccelerometer.h" namespace cocos2d { @@ -58,6 +59,8 @@ public: virtual void keep(void); virtual void didAccelerate(UIAcceleration* pAccelerationValue) {} + virtual void AccelerometerDestroy(void); + virtual void AccelerometerKeep(void); /** If isTouchEnabled, this method is called onEnter. Override it to change the way CCLayer receives touch events. diff --git a/cocos2dx/include/CCUIAccelerometerDelegate.h b/cocos2dx/include/CCUIAccelerometerDelegate.h new file mode 100644 index 0000000000..516a6ce841 --- /dev/null +++ b/cocos2dx/include/CCUIAccelerometerDelegate.h @@ -0,0 +1,61 @@ +/**************************************************************************** +Copyright (c) 2010 cocos2d-x.org + +http://www.cocos2d-x.org + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +****************************************************************************/ + +#ifndef __UIACCELEROMETER_DELEGATE_H__ +#define __UIACCELEROMETER_DELEGATE_H__ + +#include "ccxCommon.h" + +namespace cocos2d { +/** +@brief The device accelerometer reports values for each axis in units of g-force +*/ +typedef struct +{ + double x; + double y; + double z; + + double timestamp; +} UIAcceleration; + +/** +@brief +The UIAccelerometerDelegate defines a single method for +receiving acceleration-related data from the system. +*/ +class CCX_DLL UIAccelerometerDelegate +{ +public: + virtual void didAccelerate(UIAcceleration* pAccelerationValue) {} + + //! call the release() in child layer + virtual void AccelerometerDestroy(void) {} + //! call the retain() in child layer + virtual void AccelerometerKeep(void) {} +}; + +} //namespace cocos2d + +#endif diff --git a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp index a90bda7cf1..7b59f5b881 100644 --- a/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp +++ b/cocos2dx/layers_scenes_transitions_nodes/CCLayer.cpp @@ -89,6 +89,16 @@ void CCLayer::keep(void) this->retain(); } +void CCLayer::AccelerometerDestroy(void) +{ + this->release(); +} + +void CCLayer::AccelerometerKeep(void) +{ + this->retain(); +} + /// isTouchEnabled getter bool CCLayer::getIsTouchEnabled() diff --git a/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.cpp b/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.cpp index 7b3dc537dd..37476274e9 100644 --- a/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.cpp +++ b/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.cpp @@ -47,19 +47,19 @@ UIAccelerometerDelegate* UIAccelerometerHandler::getDelegate() UIAccelerometerHandler::~UIAccelerometerHandler() { - m_pDelegate->destroy(); + m_pDelegate->AccelerometerDestroy(); } void UIAccelerometerHandler::setDelegate(UIAccelerometerDelegate *pDelegate) { if (pDelegate) { - pDelegate->keep(); + pDelegate->AccelerometerKeep(); } if (m_pDelegate) { - m_pDelegate->destroy(); + m_pDelegate->AccelerometerDestroy(); } m_pDelegate = pDelegate; } @@ -69,7 +69,7 @@ bool UIAccelerometerHandler::initWithDelegate(UIAccelerometerDelegate *pDelegate assert(pDelegate != NULL); m_pDelegate = pDelegate; - pDelegate->keep(); + pDelegate->AccelerometerKeep(); return true; } diff --git a/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.h b/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.h index e83387d514..df90362737 100644 --- a/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.h +++ b/cocos2dx/platform/uphone/CCXUIAccelerometer_uphone.h @@ -25,6 +25,7 @@ THE SOFTWARE. #ifndef __PLATFORM_UPHONE_UIACCELEROMETER_H__ #define __PLATFORM_UPHONE_UIACCELEROMETER_H__ +#include "CCUIAccelerometerDelegate.h" #include "TG3.h" #include "NSMutableArray.h" #include "ccxCommon.h" @@ -32,34 +33,6 @@ THE SOFTWARE. namespace cocos2d { -/** -@brief The device accelerometer reports values for each axis in units of g-force -*/ -typedef struct -{ - double x; - double y; - double z; - - double timestamp; -} UIAcceleration; - -/** -@brief -The UIAccelerometerDelegate defines a single method for -receiving acceleration-related data from the system. -*/ -class CCX_DLL UIAccelerometerDelegate -{ -public: - virtual void didAccelerate(UIAcceleration* pAccelerationValue) {} - - //! call the release() in child layer - virtual void destroy(void) {} - //! call the retain() in child layer - virtual void keep(void) {} -}; - /** @brief UIAccelerometerHandler