在andEngine中持续更新sprite

时间:2013-01-06 11:26:36

标签: android sprite andengine

精灵(说跟踪)怎么能连续看/指向另一个精灵(比如四四方方......)我试过的东西就在这里(在onPopulate场景中)但它不起作用:(。

跟踪(当前/默认向上)

Tracky

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)));


        }
    });

1 个答案:

答案 0 :(得分:0)

抱歉,

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

应该是:

track.setRotation((float) Math.toDegrees((float) Math
                    .atan2(y_d / dtoboxy)));
相关问题