我正在使用AndEngine并且我有这个代码:
@Override
public boolean onSceneTouchEvent(TouchEvent event) {
Log.d("upd", event.getX() + "");
return true;
}
当我触摸屏幕时,会打印出如此巨大的“随机”数字:
12-10 23:27:12.352: D/upd(18109): -543629.25
12-10 23:27:12.382: D/upd(18109): -827567.5
12-10 23:27:12.412: D/upd(18109): -292541.75
12-10 23:27:12.452: D/upd(18109): -50245.75
12-10 23:27:12.482: D/upd(18109): 160085.5
12-10 23:27:12.522: D/upd(18109): 164650.38
12-10 23:27:12.562: D/upd(18109): 285486.75
12-10 23:27:12.592: D/upd(18109): 68738.0
12-10 23:27:12.622: D/upd(18109): -282403.75
12-10 23:27:12.652: D/upd(18109): -629866.25
12-10 23:27:12.692: D/upd(18109): -553627.6
等等。
答案是:
@Override
public boolean onSceneTouchEvent(TouchEvent touchEvent) {
MotionEvent event = touchEvent.getMotionEvent();
float x = event.getX();
float y = event.getY();
Log.d("upd", x + " " + y);
return true;
}