# 1 楼答案 SpriteBatch batch; int x; Sprite img; float w,h,tw,th=0; Camera camera; BitmapFont bf; @Override public void create() { bf=new BitmapFont(); w = Gdx.graphics.getWidth(); h = Gdx.graphics.getHeight(); texture = new Texture(Gdx.files.internal("android.jpg")); batch = new SpriteBatch(); camera = new OrthographicCamera(w, h); camera.position.set(w/2, h/2, 0); camera.update(); img = new Sprite(texture); tw = img.getWidth(); th = img.getHeight(); img.setBounds( camera.position.x - (tw/2), camera.position.y - (th/2),tw,th); Gdx.input.setInputProcessor(new InputAdapter(){ @Override public boolean touchDown(int screenX, int screenY, int pointer, int button) { if(img.getBoundingRectangle().contains(screenX, screenY)) System.out.println("Image Clicked"); bf.draw(batch,"click",200,200); return true; } }); } @Override public void render() { Gdx.gl.glClearColor(1, 1, 1, 1); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); batch.begin(); batch.draw(texture, x, 0); x++; if(x>=Gdx.graphics.getWidth())x=0; batch.end(); }
# 1 楼答案