Прекрасно работает в iPhoneX. В iPhone6, когда я наклоняюсь в ландшафтном режиме, значение акселерометра приходит даже в портретной игре. Как получить значение акселерометра при наклоне портрета? Игра в Портрет. Но акселерометр воспринимает это как пейзаж ..
Вот код:
Device::setAccelerometerEnabled(true);
mAccelerometerListener = EventListenerAcceleration::create(CC_CALLBACK_2( GBGameScene::onAcceleration, this));
_eventDispatcher->addEventListenerWithSceneGraphPriority(mAccelerometerListener, this);
Код акселерометра:
void GBGameScene::onAcceleration(Acceleration* acc, Event* event)
{
// Processing logic here
float deceleration = 1.0f;
float maxVelocity = 100;
playerVelocity.x = playerVelocity.x * deceleration + acc->x;
playerVelocity.y = playerVelocity.y * deceleration + acc->y;
if (playerVelocity.x > maxVelocity)
{
playerVelocity.x = maxVelocity;
}
else if (playerVelocity.x < -maxVelocity)
{
playerVelocity.x = -maxVelocity;
}
if (playerVelocity.y > maxVelocity)
{
playerVelocity.y = maxVelocity;
}
else if (playerVelocity.y < -maxVelocity)
{
playerVelocity.y = -maxVelocity;
}
// Point pos = mGravityBall->getPosition();
// pos.x += playerVelocity.x;
// mGravityBall->setPosition(pos);
}
Я не думаю, что с кодом все в порядке, так как он работает идеально в iphoneX. Почему бы не наклонить его в iPhone6?