它在屏幕上显示球但无法移动。
当加速度计改变时,我想移动球。
我怎样才能做到这一点 ??
提前致谢。
public class MainActivity extends SimpleBaseGameActivity implements IAccelerometerListener {
private static int CAMERA_WIDTH = 800;
private static int CAMERA_HEIGHT = 480;
Context ctx;
Sprite ballSprite;
private ITextureRegion mBackgroundTextureRegion,ball, mTowerTextureRegion, mRing1, mRing2, mRing3;
@Override
public EngineOptions onCreateEngineOptions() {
final Camera camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new EngineOptions(true, ScreenOrientation.LANDSCAPE_FIXED, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
}
@Override
protected void onCreateResources() {
try {
ITexture ballTexture = new BitmapTexture(this.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
return getAssets().open("ball.png");
}
});
ballTexture.load();
this.ball = TextureRegionFactory.extractFromTexture(ballTexture);
this.enableAccelerationSensor((IAccelerationListener) this);
} catch (IOException e) { e.printStackTrace(); }
}
@Override
protected Scene onCreateScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene();
ballSprite = new Sprite(0, 0, this.ball, getVertexBufferObjectManager());
scene.attachChild(ballSprite);
return scene;
}
@Override
public void onAccelerometerChanged(AccelerometerData pAccelerometerData) {
ballSprite.setPosition(ballSprite.getX() + pAccelerometerData.getX(),
ballSprite.getY() + pAccelerometerData.getY());
}
球根本不动。只是我想让它随着加速度计的变化而移动。我在其中做错了什么..??