AndEngine Tutorial: Touch & Drag Sprites

@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());


final Scene scene = new Scene(1);
scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));


final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion) {
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
this.setPosition(pSceneTouchEvent.getX() - this.getWidth() / 2, pSceneTouchEvent.getY() - this.getHeight() / 2);
return true;
}
};
face.setScale(4);
scene.getTopLayer().addEntity(face);
scene.registerTouchArea(face);
scene.setTouchAreaBindingEnabled(true);



return scene;
}

你可能感兴趣的:(AndEngine Tutorial: Touch & Drag Sprites)