倾斜控制在SDL为Android NDK JNI游戏 [英] Tilt Control in SDL for Android NDK JNI Games
问题描述
我使用使用SDL(简单直接媒体层)的Android NDK和JNI系统上C ++游戏工作。我与大部分零部件做,但我不能够计算如何实现倾斜控制(倾斜控制在寺庙运行)。我用Google搜索了很多,没有任何相关的信息。
请帮助我,我卡住了。
I am working on C++ game using android NDK and JNI system using SDL (Simple DirectMedia Layer). I am done with most of the parts but i am not able to figure how to implement tilt control (tilt control as in temple run).I have googled a lot without any relevant information. Please help me i am stuck.
Raghuvendra库马尔
Raghuvendra Kumar
推荐答案
我可以使用倾斜控制在SDL虽然我还是不明白如何与X,Y,Z值对屏幕像素位置。但至少基本操作可使用的x,y,z值来执行。由于 _ aeror 右指针。这很简单。样品测试code如下: -
I am able to use tilt control in SDL though i still don't understand how to relate x,y,z values against the screen pixel position. But at least basic operation can be performed using x,y,z values. Thanks to aeror_ for right pointers. It's very simple. Sample test code as follow:-
#include "../SDL/src/core/android/SDL_android.h"
//Get Tilt values though SDL implementation
void InputHandler::HandleTitltEvt()
{
float accelValues[3];
Android_JNI_GetAccelerometerValues(accelValues);
stTileValues_.x = accelValues[0];
stTileValues_.y = accelValues[1];
stTileValues_.z = accelValues[2];
return ;
}
//Handle TiltValues to Move your player across the screen
void Player::HandleInput_()
{
InputHandler::Instance()->HandleTitltEvt();
Axis_t tiltValues = InputHandler::Instance()->getTiltValue();
if( (tiltValues.y > 0) && ((vPosition_.getY() + iHeight_) < (Game::Instance()->getGameHeight() - 15)))
{
vVelocity_.setY(iMoveSpeed + 5);
if (tiltValues.x > 0)
{
vVelocity_.setX(iMoveSpeed+5);
}
else if (tiltValues.x < 0)
{
vVelocity_.setX(-(iMoveSpeed+5));
}
}
else if ((tiltValues.y < 0) && ((vPosition_.getY() + iHeight_) > 0))
{
vVelocity_.setY(-(iMoveSpeed+5));
if (tiltValues.x > 0)
{
vVelocity_.setX(iMoveSpeed+5);
}
else if (tiltValues.x < 0)
{
vVelocity_.setX(-(iMoveSpeed+5));
}
}
else if (tiltValues.x > 0)
{
vVelocity_.setX(iMoveSpeed+5);
}
else if (tiltValues.x < 0)
{
vVelocity_.setX(-(iMoveSpeed+5));
}
}
这篇关于倾斜控制在SDL为Android NDK JNI游戏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!