一个精灵(比如轨道)如何不断地看着/指向另一个精灵(比如四四方方)......我尝试过的东西在这里(在 onPopulate 场景中)但它不起作用:(。
轨道(当前/默认向上)
track.registerUpdateHandler(new IUpdateHandler() {
@Override
public void reset() {
}
@Override
public void onUpdate(float pSecondsElapsed) {
float centre_tracky_width = track.getWidth() / 2;
float centre_tracky_height = track.getHeight() / 2;
float centre_boxy_width = boxy.getWidth() / 2;
float centre_boxy_height = boxy.getHeight() / 2;
float x_d = (centre_tracky_width - centre_boxy_width);
float y_d = (centre_tracky_height - centre_boxy_height);
float dtoboxy = (float) Math.pow(
(float) (Math.pow(y_d, 2) + Math.pow(x_d, 2)), 0.5);
track.setRotation((float) Math.toDegrees((float) Math
.acos(y_d / dtoboxy)));
}
});