mirror of https://github.com/axmolengine/axmol.git
issue #2304:use function to simplify acceremeter call back
This commit is contained in:
parent
b91e432258
commit
ccbd0a831d
|
@ -235,11 +235,11 @@ void CCLayer::setAccelerometerEnabled(bool enabled)
|
||||||
CCDirector* pDirector = CCDirector::sharedDirector();
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(this);
|
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(CCLayer::didAccelerate, this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(NULL);
|
pDirector->getAccelerometer()->setDelegate(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -379,7 +379,7 @@ void CCLayer::onEnter()
|
||||||
// add this layer to concern the Accelerometer Sensor
|
// add this layer to concern the Accelerometer Sensor
|
||||||
if (_accelerometerEnabled)
|
if (_accelerometerEnabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(this);
|
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(CCLayer::didAccelerate, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
// add this layer to concern the keypad msg
|
// add this layer to concern the keypad msg
|
||||||
|
@ -419,7 +419,7 @@ void CCLayer::onEnterTransitionDidFinish()
|
||||||
if (_accelerometerEnabled)
|
if (_accelerometerEnabled)
|
||||||
{
|
{
|
||||||
CCDirector* pDirector = CCDirector::sharedDirector();
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
||||||
pDirector->getAccelerometer()->setDelegate(this);
|
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(CCLayer::didAccelerate, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
CCNode::onEnterTransitionDidFinish();
|
CCNode::onEnterTransitionDidFinish();
|
||||||
|
|
|
@ -60,7 +60,7 @@ All features from CCNode are valid, plus the following new features:
|
||||||
- It can receive iPhone Touches
|
- It can receive iPhone Touches
|
||||||
- It can receive Accelerometer input
|
- It can receive Accelerometer input
|
||||||
*/
|
*/
|
||||||
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
|
class CC_DLL CCLayer : public CCNode, public CCTouchDelegate, public CCKeypadDelegate
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCLayer();
|
CCLayer();
|
||||||
|
|
|
@ -43,17 +43,6 @@ public:
|
||||||
CCAcceleration(): x(0), y(0), z(0), timestamp(0) {}
|
CCAcceleration(): x(0), y(0), z(0), timestamp(0) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
@brief
|
|
||||||
The CCAccelerometerDelegate defines a single method for
|
|
||||||
receiving acceleration-related data from the system.
|
|
||||||
*/
|
|
||||||
class CC_DLL CCAccelerometerDelegate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
virtual void didAccelerate(CCAcceleration* pAccelerationValue) {CC_UNUSED_PARAM(pAccelerationValue);}
|
|
||||||
};
|
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
namespace cocos2d
|
namespace cocos2d
|
||||||
{
|
{
|
||||||
CCAccelerometer::CCAccelerometer() : _accelDelegate(NULL)
|
CCAccelerometer::CCAccelerometer() : _function(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,11 +41,11 @@ namespace cocos2d
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(std::function<void(CCAcceleration*)> function)
|
||||||
{
|
{
|
||||||
_accelDelegate = pDelegate;
|
_function = function;
|
||||||
|
|
||||||
if (pDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
enableAccelerometerJNI();
|
enableAccelerometerJNI();
|
||||||
}
|
}
|
||||||
|
@ -63,14 +63,14 @@ namespace cocos2d
|
||||||
|
|
||||||
void CCAccelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
void CCAccelerometer::update(float x, float y, float z, long sensorTimeStamp)
|
||||||
{
|
{
|
||||||
if (_accelDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
_accelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
|
_accelerationValue.x = -((double)x / TG3_GRAVITY_EARTH);
|
||||||
_accelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
|
_accelerationValue.y = -((double)y / TG3_GRAVITY_EARTH);
|
||||||
_accelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
|
_accelerationValue.z = -((double)z / TG3_GRAVITY_EARTH);
|
||||||
_accelerationValue.timestamp = (double)sensorTimeStamp;
|
_accelerationValue.timestamp = (double)sensorTimeStamp;
|
||||||
|
|
||||||
_accelDelegate->didAccelerate(&_accelerationValue);
|
_function(&_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // end of namespace cococs2d
|
} // end of namespace cococs2d
|
||||||
|
|
|
@ -27,21 +27,22 @@ THE SOFTWARE.
|
||||||
|
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
class CC_DLL CCAccelerometer
|
class CCAccelerometer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval);
|
void setAccelerometerInterval(float interval);
|
||||||
void update(float x, float y, float z, long sensorTimeStamp);
|
void update(float x, float y, float z, long sensorTimeStamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCAccelerometerDelegate* _accelDelegate;
|
std::function<void(CCAcceleration*)> _function;
|
||||||
CCAcceleration _accelerationValue;
|
CCAcceleration _accelerationValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ int CCAccelerometer::_initialOrientationAngle = 0;
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer()
|
CCAccelerometer::CCAccelerometer()
|
||||||
{
|
{
|
||||||
_accelDelegate = NULL;
|
_function = nullptr;
|
||||||
_initialOrientationAngle = atoi(getenv("ORIENTATION"));
|
_initialOrientationAngle = atoi(getenv("ORIENTATION"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ CCAccelerometer::~CCAccelerometer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(std::function<void(CCAcceleration*)> function)
|
||||||
{
|
{
|
||||||
_accelDelegate = pDelegate;
|
_function = function;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::update(long timeStamp, double x, double y, double z)
|
void CCAccelerometer::update(long timeStamp, double x, double y, double z)
|
||||||
{
|
{
|
||||||
if ( _accelDelegate != NULL)
|
if ( _function != NULL)
|
||||||
{
|
{
|
||||||
if (getenv("WIDTH"))
|
if (getenv("WIDTH"))
|
||||||
{
|
{
|
||||||
|
@ -81,7 +81,7 @@ void CCAccelerometer::update(long timeStamp, double x, double y, double z)
|
||||||
_accelerationValue.z = z;
|
_accelerationValue.z = z;
|
||||||
_accelerationValue.timestamp = (double)timeStamp;
|
_accelerationValue.timestamp = (double)timeStamp;
|
||||||
|
|
||||||
_accelDelegate->didAccelerate(&_accelerationValue);
|
_function(&_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@ THE SOFTWARE.
|
||||||
#ifndef __PLATFORM_CCACCELEROMETER_BLACKBERRY_H__
|
#ifndef __PLATFORM_CCACCELEROMETER_BLACKBERRY_H__
|
||||||
#define __PLATFORM_CCACCELEROMETER_BLACKBERRY_H__
|
#define __PLATFORM_CCACCELEROMETER_BLACKBERRY_H__
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
@ -35,12 +36,12 @@ public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
||||||
void update(long sensorTimeStamp, double x, double y, double z);
|
void update(long sensorTimeStamp, double x, double y, double z);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCAccelerometerDelegate* _accelDelegate;
|
std::function<void(CCAcceleration*)> _function;
|
||||||
CCAcceleration _accelerationValue;
|
CCAcceleration _accelerationValue;
|
||||||
static int _initialOrientationAngle;
|
static int _initialOrientationAngle;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define CCACCELEROMETER_H_
|
#define CCACCELEROMETER_H_
|
||||||
|
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -20,9 +21,9 @@ public:
|
||||||
|
|
||||||
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
||||||
|
|
||||||
void removeDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void removeDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void addDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void addDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void setDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,43 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
|
||||||
#import "CCAccelerometerDelegate.h"
|
|
||||||
#import <UIKit/UIKit.h>
|
|
||||||
|
|
||||||
@interface AccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
|
|
||||||
{
|
|
||||||
cocos2d::CCAccelerometerDelegate *delegate_;
|
|
||||||
cocos2d::CCAcceleration *acceleration_;
|
|
||||||
}
|
|
||||||
|
|
||||||
@property(readwrite) cocos2d::CCAccelerometerDelegate *delegate_;
|
|
||||||
@property(readwrite) cocos2d::CCAcceleration *acceleration_;
|
|
||||||
|
|
||||||
+ (id) sharedAccelerometerDispather;
|
|
||||||
- (id) init;
|
|
||||||
- (void) addDelegate: (cocos2d::CCAccelerometerDelegate *) delegate;
|
|
||||||
- (void) setAccelerometerInterval:(float)interval;
|
|
||||||
|
|
||||||
@end
|
|
|
@ -1,115 +0,0 @@
|
||||||
/****************************************************************************
|
|
||||||
Copyright (c) 2010 cocos2d-x.org
|
|
||||||
|
|
||||||
http://www.cocos2d-x.org
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in
|
|
||||||
all copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
THE SOFTWARE.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#import "AccelerometerDelegateWrapper.h"
|
|
||||||
|
|
||||||
@implementation AccelerometerDispatcher
|
|
||||||
|
|
||||||
static AccelerometerDispatcher* s_pAccelerometerDispatcher;
|
|
||||||
|
|
||||||
@synthesize delegate_;
|
|
||||||
@synthesize acceleration_;
|
|
||||||
|
|
||||||
+ (id) sharedAccelerometerDispather
|
|
||||||
{
|
|
||||||
if (s_pAccelerometerDispatcher == nil) {
|
|
||||||
s_pAccelerometerDispatcher = [[self alloc] init];
|
|
||||||
}
|
|
||||||
|
|
||||||
return s_pAccelerometerDispatcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (id) init
|
|
||||||
{
|
|
||||||
acceleration_ = new cocos2d::CCAcceleration();
|
|
||||||
return self;
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) dealloc
|
|
||||||
{
|
|
||||||
s_pAccelerometerDispatcher = 0;
|
|
||||||
delegate_ = 0;
|
|
||||||
delete acceleration_;
|
|
||||||
[super dealloc];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void) addDelegate: (cocos2d::CCAccelerometerDelegate *) delegate
|
|
||||||
{
|
|
||||||
delegate_ = delegate;
|
|
||||||
|
|
||||||
if (delegate_)
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
-(void) setAccelerometerInterval:(float)interval
|
|
||||||
{
|
|
||||||
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:interval];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
|
|
||||||
{
|
|
||||||
if (! delegate_)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
acceleration_->x = acceleration.x;
|
|
||||||
acceleration_->y = acceleration.y;
|
|
||||||
acceleration_->z = acceleration.z;
|
|
||||||
acceleration_->timestamp = acceleration.timestamp;
|
|
||||||
|
|
||||||
double tmp = acceleration_->x;
|
|
||||||
|
|
||||||
switch ([[UIApplication sharedApplication] statusBarOrientation])
|
|
||||||
{
|
|
||||||
case UIInterfaceOrientationLandscapeRight:
|
|
||||||
acceleration_->x = -acceleration_->y;
|
|
||||||
acceleration_->y = tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationLandscapeLeft:
|
|
||||||
acceleration_->x = acceleration_->y;
|
|
||||||
acceleration_->y = -tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationPortraitUpsideDown:
|
|
||||||
acceleration_->x = -acceleration_->y;
|
|
||||||
acceleration_->y = -tmp;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case UIInterfaceOrientationPortrait:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
delegate_->didAccelerate(acceleration_);
|
|
||||||
}
|
|
||||||
|
|
||||||
@end
|
|
||||||
|
|
|
@ -25,17 +25,18 @@ THE SOFTWARE.
|
||||||
#ifndef __PLATFORM_IPHONE_CCACCELEROMETER_H__
|
#ifndef __PLATFORM_IPHONE_CCACCELEROMETER_H__
|
||||||
#define __PLATFORM_IPHONE_CCACCELEROMETER_H__
|
#define __PLATFORM_IPHONE_CCACCELEROMETER_H__
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class CC_DLL CCAccelerometer
|
class CCAccelerometer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval);
|
void setAccelerometerInterval(float interval);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -23,21 +23,124 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#include "CCAccelerometer.h"
|
#include "CCAccelerometer.h"
|
||||||
#include "AccelerometerDelegateWrapper.h"
|
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
#import "CCAccelerometerDelegate.h"
|
||||||
|
#import <UIKit/UIKit.h>
|
||||||
|
#import <functional>
|
||||||
|
|
||||||
|
@interface AccelerometerDispatcher : NSObject<UIAccelerometerDelegate>
|
||||||
|
{
|
||||||
|
std::function<void(cocos2d::CCAcceleration*)> _function;
|
||||||
|
cocos2d::CCAcceleration *_acceleration;
|
||||||
|
}
|
||||||
|
|
||||||
|
+ (id) sharedAccelerometerDispather;
|
||||||
|
- (id) init;
|
||||||
|
- (void) addDelegate: (std::function<void(cocos2d::CCAcceleration*)>) function;
|
||||||
|
- (void) setAccelerometerInterval:(float)interval;
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation AccelerometerDispatcher
|
||||||
|
|
||||||
|
static AccelerometerDispatcher* s_pAccelerometerDispatcher;
|
||||||
|
|
||||||
|
+ (id) sharedAccelerometerDispather
|
||||||
|
{
|
||||||
|
if (s_pAccelerometerDispatcher == nil) {
|
||||||
|
s_pAccelerometerDispatcher = [[self alloc] init];
|
||||||
|
}
|
||||||
|
|
||||||
|
return s_pAccelerometerDispatcher;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (id) init
|
||||||
|
{
|
||||||
|
_acceleration = new cocos2d::CCAcceleration();
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) dealloc
|
||||||
|
{
|
||||||
|
s_pAccelerometerDispatcher = nullptr;
|
||||||
|
_function = nullptr;
|
||||||
|
delete _acceleration;
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void) addDelegate: (std::function<void(cocos2d::CCAcceleration*)>) function
|
||||||
|
{
|
||||||
|
_function = function;
|
||||||
|
|
||||||
|
if (_function)
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setDelegate:self];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setDelegate:nil];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
-(void) setAccelerometerInterval:(float)interval
|
||||||
|
{
|
||||||
|
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:interval];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
|
||||||
|
{
|
||||||
|
if (! _function)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_acceleration->x = acceleration.x;
|
||||||
|
_acceleration->y = acceleration.y;
|
||||||
|
_acceleration->z = acceleration.z;
|
||||||
|
_acceleration->timestamp = acceleration.timestamp;
|
||||||
|
|
||||||
|
double tmp = _acceleration->x;
|
||||||
|
|
||||||
|
switch ([[UIApplication sharedApplication] statusBarOrientation])
|
||||||
|
{
|
||||||
|
case UIInterfaceOrientationLandscapeRight:
|
||||||
|
_acceleration->x = -_acceleration->y;
|
||||||
|
_acceleration->y = tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationLandscapeLeft:
|
||||||
|
_acceleration->x = _acceleration->y;
|
||||||
|
_acceleration->y = -tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationPortraitUpsideDown:
|
||||||
|
_acceleration->x = -_acceleration->y;
|
||||||
|
_acceleration->y = -tmp;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case UIInterfaceOrientationPortrait:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
_function(_acceleration);
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
/** Implementation of CCAccelerometer
|
||||||
|
*/
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
CCAccelerometer::~CCAccelerometer()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
CCAccelerometer::CCAccelerometer() {}
|
||||||
|
|
||||||
|
CCAccelerometer::~CCAccelerometer() {}
|
||||||
|
|
||||||
|
void CCAccelerometer::setDelegate(std::function<void (CCAcceleration *)> function)
|
||||||
{
|
{
|
||||||
[[AccelerometerDispatcher sharedAccelerometerDispather] addDelegate:pDelegate];
|
[[AccelerometerDispatcher sharedAccelerometerDispather] addDelegate:function];
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setAccelerometerInterval(float interval)
|
void CCAccelerometer::setAccelerometerInterval(float interval)
|
||||||
|
@ -46,4 +149,3 @@ void CCAccelerometer::setAccelerometerInterval(float interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -123,29 +123,6 @@ static bool _initWithImage(CGImageRef cgImage, tImageInfo *pImageinfo)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool _initWithFile(const char* path, tImageInfo *pImageinfo)
|
|
||||||
{
|
|
||||||
CGImageRef CGImage;
|
|
||||||
UIImage *jpg;
|
|
||||||
UIImage *png;
|
|
||||||
bool ret;
|
|
||||||
|
|
||||||
// convert jpg to png before loading the texture
|
|
||||||
|
|
||||||
NSString *fullPath = [NSString stringWithUTF8String:path];
|
|
||||||
jpg = [[UIImage alloc] initWithContentsOfFile: fullPath];
|
|
||||||
png = [[UIImage alloc] initWithData:UIImagePNGRepresentation(jpg)];
|
|
||||||
CGImage = png.CGImage;
|
|
||||||
|
|
||||||
ret = _initWithImage(CGImage, pImageinfo);
|
|
||||||
|
|
||||||
[png release];
|
|
||||||
[jpg release];
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo)
|
static bool _initWithData(void * pBuffer, int length, tImageInfo *pImageinfo)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
|
@ -482,7 +459,7 @@ bool CCImage::initWithImageData(void * pData,
|
||||||
CC_BREAK_IF(! pData || nDataLen <= 0);
|
CC_BREAK_IF(! pData || nDataLen <= 0);
|
||||||
if (eFmt == kFmtRawData)
|
if (eFmt == kFmtRawData)
|
||||||
{
|
{
|
||||||
bRet = _initWithRawData(pData, nDataLen, nWidth, nHeight, nBitsPerComponent, false);
|
bRet = initWithRawData(pData, nDataLen, nWidth, nHeight, nBitsPerComponent, false);
|
||||||
}
|
}
|
||||||
else if (eFmt == kFmtWebp)
|
else if (eFmt == kFmtWebp)
|
||||||
{
|
{
|
||||||
|
@ -506,7 +483,7 @@ bool CCImage::initWithImageData(void * pData,
|
||||||
return bRet;
|
return bRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCImage::_initWithRawData(void *pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent, bool bPreMulti)
|
bool CCImage::initWithRawData(void *pData, int nDatalen, int nWidth, int nHeight, int nBitsPerComponent, bool bPreMulti)
|
||||||
{
|
{
|
||||||
bool bRet = false;
|
bool bRet = false;
|
||||||
do
|
do
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#define CCACCELEROMETER_H_
|
#define CCACCELEROMETER_H_
|
||||||
|
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -20,9 +21,9 @@ public:
|
||||||
|
|
||||||
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
||||||
|
|
||||||
void removeDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void removeDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void addDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void addDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void setDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ namespace cocos2d
|
||||||
|
|
||||||
CCAccelerometer* CCAccelerometer::_spCCAccelerometer = NULL;
|
CCAccelerometer* CCAccelerometer::_spCCAccelerometer = NULL;
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer() : _accelDelegate(NULL)
|
CCAccelerometer::CCAccelerometer() : _function(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,11 +53,11 @@ CCAccelerometer* CCAccelerometer::sharedAccelerometer()
|
||||||
return _spCCAccelerometer;
|
return _spCCAccelerometer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(std::function<void(CCAcceleration*)> function)
|
||||||
{
|
{
|
||||||
_accelDelegate = pDelegate;
|
_function = function;
|
||||||
|
|
||||||
if (pDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
if (s3eAccelerometerStart() != S3E_RESULT_SUCCESS)
|
if (s3eAccelerometerStart() != S3E_RESULT_SUCCESS)
|
||||||
{
|
{
|
||||||
|
@ -72,14 +72,14 @@ void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
||||||
|
|
||||||
void CCAccelerometer::update(float x, float y, float z, uint64 sensorTimeStamp)
|
void CCAccelerometer::update(float x, float y, float z, uint64 sensorTimeStamp)
|
||||||
{
|
{
|
||||||
if (_accelDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
_accelerationValue.x = ((double)x)/S3E_ACCELEROMETER_1G ;
|
_accelerationValue.x = ((double)x)/S3E_ACCELEROMETER_1G ;
|
||||||
_accelerationValue.y = ((double)y)/S3E_ACCELEROMETER_1G ;
|
_accelerationValue.y = ((double)y)/S3E_ACCELEROMETER_1G ;
|
||||||
_accelerationValue.z = ((double)z)/S3E_ACCELEROMETER_1G ;
|
_accelerationValue.z = ((double)z)/S3E_ACCELEROMETER_1G ;
|
||||||
_accelerationValue.timestamp = (double)(sensorTimeStamp / 1000.0);
|
_accelerationValue.timestamp = (double)(sensorTimeStamp / 1000.0);
|
||||||
|
|
||||||
_accelDelegate->didAccelerate(&_accelerationValue);
|
_function(&_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#include "CCAccelerometerDelegate.h"
|
#include "CCAccelerometerDelegate.h"
|
||||||
//#include "CCMutableArray.h"
|
//#include "CCMutableArray.h"
|
||||||
#include "ccCommon.h"
|
#include "ccCommon.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -47,13 +47,13 @@ public:
|
||||||
*/
|
*/
|
||||||
static CCAccelerometer* sharedAccelerometer();
|
static CCAccelerometer* sharedAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
||||||
void update(float x, float y, float z, uint64 sensorTimeStamp);
|
void update(float x, float y, float z, uint64 sensorTimeStamp);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static CCAccelerometer* _spCCAccelerometer;
|
static CCAccelerometer* _spCCAccelerometer;
|
||||||
CCAccelerometerDelegate* _accelDelegate;
|
std::function<void(CCAcceleration*)> _function;
|
||||||
CCAcceleration _accelerationValue;
|
CCAcceleration _accelerationValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
||||||
#define __CCACCELEROMETER_H__
|
#define __CCACCELEROMETER_H__
|
||||||
|
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace cocos2d {
|
namespace cocos2d {
|
||||||
|
|
||||||
|
@ -37,8 +38,8 @@ public:
|
||||||
|
|
||||||
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
static CCAccelerometer* sharedAccelerometer() { return NULL; };
|
||||||
|
|
||||||
void removeDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void removeDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void addDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void addDelegate(std::function<void(CCAcceleration*)> function) {CC_UNUSED_PARAM(function);};
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
void setDelegate(CCAccelerometerDelegate* pDelegate) {CC_UNUSED_PARAM(pDelegate);};
|
||||||
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
void setAccelerometerInterval(float interval) {CC_UNUSED_PARAM(interval);};
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,8 +30,8 @@ using namespace Tizen::Uix::Sensor;
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer()
|
CCAccelerometer::CCAccelerometer()
|
||||||
: _accelDelegate(NULL)
|
: _function(nullptr)
|
||||||
, __sensorMgr(NULL)
|
, __sensorMgr(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,11 +40,11 @@ CCAccelerometer::~CCAccelerometer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(std::function<void(CCAcceleration*)> function)
|
||||||
{
|
{
|
||||||
_accelDelegate = pDelegate;
|
_function = function;
|
||||||
|
|
||||||
if (pDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
startSensor();
|
startSensor();
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ void CCAccelerometer::stopSensor()
|
||||||
|
|
||||||
void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorData , result r)
|
void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorData , result r)
|
||||||
{
|
{
|
||||||
if (_accelDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
AccelerationSensorData& data = static_cast<AccelerationSensorData&>(sensorData);
|
AccelerationSensorData& data = static_cast<AccelerationSensorData&>(sensorData);
|
||||||
AppLog("AccelerationSensorData x = %5.4f , y = %5.4f, z = %5.4f ", data.x,data.y,data.z);
|
AppLog("AccelerationSensorData x = %5.4f , y = %5.4f, z = %5.4f ", data.x,data.y,data.z);
|
||||||
|
@ -107,7 +107,7 @@ void CCAccelerometer::OnDataReceived(SensorType sensorType, SensorData& sensorDa
|
||||||
_accelerationValue.z = -data.z;
|
_accelerationValue.z = -data.z;
|
||||||
_accelerationValue.timestamp = data.timestamp;
|
_accelerationValue.timestamp = data.timestamp;
|
||||||
|
|
||||||
_accelDelegate->didAccelerate(&_accelerationValue);
|
_function(&_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,7 @@ THE SOFTWARE.
|
||||||
#include "platform/CCCommon.h"
|
#include "platform/CCCommon.h"
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
#include <FUix.h>
|
#include <FUix.h>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval);
|
void setAccelerometerInterval(float interval);
|
||||||
void startSensor();
|
void startSensor();
|
||||||
void stopSensor();
|
void stopSensor();
|
||||||
|
@ -46,7 +47,7 @@ public:
|
||||||
virtual void OnDataReceived(Tizen::Uix::Sensor::SensorType sensorType, Tizen::Uix::Sensor::SensorData& sensorData , result r);
|
virtual void OnDataReceived(Tizen::Uix::Sensor::SensorType sensorType, Tizen::Uix::Sensor::SensorData& sensorData , result r);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CCAccelerometerDelegate* _accelDelegate;
|
std::function<void(CCAcceleration*)> _function;
|
||||||
CCAcceleration _accelerationValue;
|
CCAcceleration _accelerationValue;
|
||||||
Tizen::Uix::Sensor::SensorManager* __sensorMgr;
|
Tizen::Uix::Sensor::SensorManager* __sensorMgr;
|
||||||
};
|
};
|
||||||
|
|
|
@ -148,7 +148,7 @@ namespace
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
CCAccelerometer::CCAccelerometer() :
|
CCAccelerometer::CCAccelerometer() :
|
||||||
_accelDelegate(NULL)
|
_function(nullptr)
|
||||||
{
|
{
|
||||||
memset(&_accelerationValue, 0, sizeof(_accelerationValue));
|
memset(&_accelerationValue, 0, sizeof(_accelerationValue));
|
||||||
}
|
}
|
||||||
|
@ -158,14 +158,14 @@ CCAccelerometer::~CCAccelerometer()
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCAccelerometer::setDelegate(CCAccelerometerDelegate* pDelegate)
|
void CCAccelerometer::setDelegate(std::function<void(CCAcceleration*)> function)
|
||||||
{
|
{
|
||||||
_accelDelegate = pDelegate;
|
_function = function;
|
||||||
|
|
||||||
// Enable/disable the accelerometer.
|
// Enable/disable the accelerometer.
|
||||||
// Well, there isn't one on Win32 so we don't do anything other than register
|
// Well, there isn't one on Win32 so we don't do anything other than register
|
||||||
// and deregister ourselves from the Windows Key handler.
|
// and deregister ourselves from the Windows Key handler.
|
||||||
if (pDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
// Register our handler
|
// Register our handler
|
||||||
CCEGLView::sharedOpenGLView()->setAccelerometerKeyHook( &myAccelerometerKeyHook );
|
CCEGLView::sharedOpenGLView()->setAccelerometerKeyHook( &myAccelerometerKeyHook );
|
||||||
|
@ -185,7 +185,7 @@ void CCAccelerometer::setAccelerometerInterval(float interval)
|
||||||
|
|
||||||
void CCAccelerometer::update( double x,double y,double z,double timestamp )
|
void CCAccelerometer::update( double x,double y,double z,double timestamp )
|
||||||
{
|
{
|
||||||
if (_accelDelegate)
|
if (_function)
|
||||||
{
|
{
|
||||||
_accelerationValue.x = x;
|
_accelerationValue.x = x;
|
||||||
_accelerationValue.y = y;
|
_accelerationValue.y = y;
|
||||||
|
@ -193,7 +193,7 @@ void CCAccelerometer::update( double x,double y,double z,double timestamp )
|
||||||
_accelerationValue.timestamp = timestamp;
|
_accelerationValue.timestamp = timestamp;
|
||||||
|
|
||||||
// Delegate
|
// Delegate
|
||||||
_accelDelegate->didAccelerate(&_accelerationValue);
|
_function(&_accelerationValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ THE SOFTWARE.
|
||||||
#define __PLATFORM_WIN32_UIACCELEROMETER_H__
|
#define __PLATFORM_WIN32_UIACCELEROMETER_H__
|
||||||
|
|
||||||
#include "platform/CCAccelerometerDelegate.h"
|
#include "platform/CCAccelerometerDelegate.h"
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
@ -35,12 +36,12 @@ public:
|
||||||
CCAccelerometer();
|
CCAccelerometer();
|
||||||
~CCAccelerometer();
|
~CCAccelerometer();
|
||||||
|
|
||||||
void setDelegate(CCAccelerometerDelegate* pDelegate);
|
void setDelegate(std::function<void(CCAcceleration*)> function);
|
||||||
void setAccelerometerInterval(float interval);
|
void setAccelerometerInterval(float interval);
|
||||||
void update( double x,double y,double z,double timestamp );
|
void update( double x,double y,double z,double timestamp );
|
||||||
private:
|
private:
|
||||||
CCAcceleration _accelerationValue;
|
CCAcceleration _accelerationValue;
|
||||||
CCAccelerometerDelegate* _accelDelegate;
|
std::function<void(CCAcceleration*)> _function;
|
||||||
};
|
};
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
06a3716ff2fdcaa883bed71ffe53793daf0f3980
|
08c5c5cd8dcd5b6d72678c72cd156682e33f8553
|
|
@ -174,11 +174,11 @@ void CCInputDelegate::setAccelerometerEnabled(bool enabled)
|
||||||
CCDirector* pDirector = CCDirector::sharedDirector();
|
CCDirector* pDirector = CCDirector::sharedDirector();
|
||||||
if (enabled)
|
if (enabled)
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(this);
|
pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(CCInputDelegate::didAccelerate, this));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pDirector->getAccelerometer()->setDelegate(NULL);
|
pDirector->getAccelerometer()->setDelegate(nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ THE SOFTWARE.
|
||||||
|
|
||||||
NS_CC_EXT_BEGIN
|
NS_CC_EXT_BEGIN
|
||||||
|
|
||||||
class CCInputDelegate : public CCTouchDelegate, public CCAccelerometerDelegate, public CCKeypadDelegate
|
class CCInputDelegate : public CCTouchDelegate, public CCKeypadDelegate
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
CCInputDelegate(void);
|
CCInputDelegate(void);
|
||||||
|
|
Loading…
Reference in New Issue