我有这样的问题:我的传感器大部分工作正常。但有时传感器在三星 Galaxy Gio 上不起作用。可能是关于设备规格。在运行时我得到了这个错误,但没有产生崩溃。只是传感器不起作用,我的球不会通过传感器产生的重力移动。
01-04 01:40:56.924: E/SensorManager(30236): registerListener :: handle = 0 name= BMA220 delay= 60 Listener= com.serefakyuz.com.utils.Engine@4a507950
01-04 01:40:56.924: E/SensorManager(30236): =======>>>Sensor Thread RUNNING <<<========
01-04 01:40:56.934: E/SensorHAL(30236): __data_data_open 31 32
01-04 01:43:03.376: E/SensorManager(30326): registerListener :: handle = 0 name= BMA220 delay= 60 Listener= com.serefakyuz.com.utils.Engine@4a507930
这是我刷新重力的代码:
@Override
public void onAccelerometerChanged(AccelerometerData pAccelerometerData)
{
float k = 10f;
Vector2 gravity = null;
if(mLevelScene.isWaterExist)
{
if((mLevelScene.ballPlayer.oAnimatedSprite.getX() > mLevelScene.waterCoordinates[0] && mLevelScene.ballPlayer.oAnimatedSprite.getX() < mLevelScene.waterCoordinates[0] + mLevelScene.water.oTextureWidth) &&
(mLevelScene.ballPlayer.oAnimatedSprite.getY() + 32 > mLevelScene.waterCoordinates[1] && mLevelScene.ballPlayer.oAnimatedSprite.getY() < mLevelScene.waterCoordinates[1] + mLevelScene.water.oTextureHeight))
{
gravity = Vector2Pool.obtain(pAccelerometerData.getX()*k, pAccelerometerData.getY()*k - ( (mLevelScene.ballPlayer.oAnimatedSprite.getY() - mLevelScene.water.oSprite.getY())*3/4 + 20));
mDampingCount = 2.0f;
}
else
{
gravity = Vector2Pool.obtain(pAccelerometerData.getX()*k, pAccelerometerData.getY()*k);
mDampingCount = 1.5f;
}
}
else
{
gravity = Vector2Pool.obtain(pAccelerometerData.getX()*k, pAccelerometerData.getY()*k);
mDampingCount = 1.5f;
}
mPhysicsWorld.setGravity(gravity);
Vector2Pool.recycle(gravity);
}