我是LibGdx新手,并试图使我的iceCream图像可触摸.我想知道如何设置输入过程(通过触摸屏幕).我需要再上一堂课吗?当我尝试将输入过程实现到我的Prac1类时,JAVA不允许我在不改变类抽象的情况下实现.具体来说,我喜欢在用户触摸图像时制作它,它会计算触摸次数.这是我的代码,谢谢你的帮助.
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;
public class Prac1 extends ApplicationAdapter {
int w,h,tw,th =0;
OrthographicCamera camera;
SpriteBatch batch;
Texture img;
@Override
public void create () {
w = Gdx.graphics.getWidth();
h = Gdx.graphics.getHeight();
camera = new OrthographicCamera(w, h);
camera.position.set(w/2, h/2, 0);
camera.update();
batch = new SpriteBatch();
img = new Texture(Gdx.files.internal("iceCream.png"));
tw = img.getWidth();
th = img.getHeight();
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(img, camera.position.x - (tw/2), …Run Code Online (Sandbox Code Playgroud)