0

一个精灵(比如轨道)如何不断地看着/指向另一个精灵(比如四四方方)......我尝试过的东西在这里(在 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)));


        }
    });
4

1 回答 1

0

对不起,

track.setRotation((float) Math.toDegrees((float) Math
                    .acos(y_d / dtoboxy)));

应该 :

track.setRotation((float) Math.toDegrees((float) Math
                    .atan2(y_d / dtoboxy)));
于 2013-04-13T07:48:03.250 回答