need to reset the accelerometer before trying to enable it again

This commit is contained in:
Dale Stammen 2014-09-23 10:01:42 -07:00
parent a5724a5be4
commit 2226aa5c8a
1 changed files with 8 additions and 11 deletions

View File

@ -54,6 +54,14 @@ void Device::setAccelerometerEnabled(bool isEnabled)
static Windows::Foundation::EventRegistrationToken sToken;
static bool sEnabled = false;
// we always need to reset the accelerometer
if (sAccelerometer)
{
sAccelerometer->ReadingChanged -= sToken;
sAccelerometer = nullptr;
sEnabled = false;
}
if (isEnabled)
{
sAccelerometer = Accelerometer::GetDefault();
@ -118,17 +126,6 @@ void Device::setAccelerometerEnabled(bool isEnabled)
cocos2d::GLViewImpl::sharedOpenGLView()->QueueEvent(event);
});
}
else
{
if (sAccelerometer)
{
sAccelerometer->ReadingChanged -= sToken;
sAccelerometer = nullptr;
}
sEnabled = false;
}
}
void Device::setAccelerometerInterval(float interval)