图像未指向(旋转)您触摸的位置

时间:2014-03-27 16:41:08

标签: java android

所以我正在制作安卓游戏,我试图让你的武器点在你触摸的地方。

编辑:仍然没有工作,没有错误,但它没有旋转。

public boolean onSceneTouchEvent(Vector3 touch, OrthographicCamera camera) {
    if (Gdx.input.justTouched()) {
        touch.set(Gdx.input.getX(), Gdx.input.getY(), 0);
        camera.unproject(touch);

        float finalX = Assets.sprite_guy.getX() - touch.x;
        float finalY = Assets.sprite_guy.getY() - touch.y;      

        float rotationInRad = (float) Math.atan2(finalY, finalX);
        float rotationInDeg = (float) Math.toDegrees(rotationInRad);


        Assets.sprite_guy.setRotation(rotationInDeg);

    }
    return true;
}

这是在Assets.java

    texture_guy = new Texture(Gdx.files.internal("data/Guy.png"));
    texture_guy.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    sprite_guy = new Sprite(texture_guy);
    sprite_guy.flip(false, true);
编辑:仍然没有解决这个问题。

1 个答案:

答案 0 :(得分:0)

尝试将xml与两个不同的定位图像一起使用,如:

 <?xml version="1.0" encoding="utf-8"?>
 <selector
xmlns:android="http://schemas.android.    com/apk/res/android">

     <item
android:state_pressed="true"
android:drawable="@drawable/    weapon_clicked" />


  <item
android:state_focused=
"true"
android:drawable="@drawable/weapon_clicked"/>

     <item
android:drawable="@drawable/    weapon_original" /> 
 </selector>