Example #1
0
/// Callbacks
void Layer::onEnter()
{
    Director* pDirector = Director::getInstance();
    // register 'parent' nodes first
    // since events are propagated in reverse order
    if (_touchEnabled)
    {
        this->registerWithTouchDispatcher();
    }

    // then iterate over all the children
    Node::onEnter();

    // add this layer to concern the Accelerometer Sensor
    if (_accelerometerEnabled)
    {
        pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
    }

    // add this layer to concern the keypad msg
    if (_keypadEnabled)
    {
        pDirector->getKeypadDispatcher()->addDelegate(this);
    }
}
Example #2
0
void Layer::onEnterTransitionDidFinish()
{
    if (_accelerometerEnabled)
    {
        Director* pDirector = Director::getInstance();
        pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
    }
    
    Node::onEnterTransitionDidFinish();
}
Example #3
0
void Layer::setAccelerometerInterval(double interval) {
    if (_accelerometerEnabled)
    {
        if (_running)
        {
            Director* pDirector = Director::getInstance();
            pDirector->getAccelerometer()->setAccelerometerInterval(interval);
        }
    }
}
Example #4
0
/// isAccelerometerEnabled setter
void Layer::setAccelerometerEnabled(bool enabled)
{
    if (enabled != _accelerometerEnabled)
    {
        _accelerometerEnabled = enabled;

        if (_running)
        {
            Director* pDirector = Director::getInstance();
            if (enabled)
            {
                pDirector->getAccelerometer()->setDelegate(CC_CALLBACK_1(Layer::didAccelerate, this));
            }
            else
            {
                pDirector->getAccelerometer()->setDelegate(nullptr);
            }
        }
    }
}
Example #5
0
void Layer::onExit()
{
    Director* pDirector = Director::getInstance();
    if( _touchEnabled )
    {
        pDirector->getTouchDispatcher()->removeDelegate(this);
    }

    // remove this layer from the delegates who concern Accelerometer Sensor
    if (_accelerometerEnabled)
    {
		pDirector->getAccelerometer()->setDelegate(nullptr);
    }

    // remove this layer from the delegates who concern the keypad msg
    if (_keypadEnabled)
    {
        pDirector->getKeypadDispatcher()->removeDelegate(this);
    }

    Node::onExit();
}
 JNIEXPORT void JNICALL Java_org_cocos2dx_lib_Cocos2dxAccelerometer_onSensorChanged(JNIEnv*  env, jobject thiz, jfloat x, jfloat y, jfloat z, jlong timeStamp) {
     Director* pDirector = Director::getInstance();
     pDirector->getAccelerometer()->update(x, y, z, timeStamp);
 }