私はこのコードを使用していますが、何かが完璧ではありません。それは働いているが滑らかではない。最初にtouchXに行き、touchYになります。しかし、私はこれを同時に望みます。私は別のコードを試みたが、うまくいかなかった。どうすれば修正できますか?どうしたの?このセクションではJava LibGDX Androidのタッチ位置に移動
package com.anil.game1;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector3;
public class Game1 extends ApplicationAdapter {
private SpriteBatch batch;
private OrthographicCamera camera;
private Texture player1Texture;
private Rectangle player1Rectangle;
private Vector3 touchPos;
@Override
public void create() {
batch = new SpriteBatch();
camera = new OrthographicCamera(480, 800);
player1Texture = new Texture("Player1.png");
player1Rectangle = new Rectangle();
player1Rectangle.set(240, 0, 64, 64);
touchPos = new Vector3();
}
@Override
public void render() {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
if (Gdx.input.isTouched()) {
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
//player1Rectangle.setPosition(new Vector2(touchPos.x, touchPos.y));
}
if (touchPos.x > player1Rectangle.x)
player1Rectangle.x += 5;
else
player1Rectangle.x -= 5;
if (touchPos.y > player1Rectangle.y)
player1Rectangle.y += 5;
else
player1Rectangle.y -= 5;
batch.draw(player1Texture, player1Rectangle.x - 32, player1Rectangle.y - 32);
batch.end();
}
@Override
public void dispose() {
batch.dispose();
player1Texture.dispose();
}
}
、チェックマークを使用して、以下の答えをしてください受け入れます。それがここで解決された投稿をマークする方法です。 –