Java LibGdx,在屏幕上呈现计数整数
现在程序可以将数字计数到31,我想让它在屏幕上呈现Java LibGdx,在屏幕上呈现计数整数,java,libgdx,Java,Libgdx,现在程序可以将数字计数到31,我想让它在屏幕上呈现count整数变量。我尝试了batch.draw(Integer.toString(count))并尝试了font.draw(批处理,整数.toString(计数),25160)都给了我JAVA中的错误(语法错误)。请给我一些建议。多谢各位~ package com.mygdx.game; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; impor
count
整数变量。我尝试了batch.draw(Integer.toString(count))
并尝试了font.draw(批处理,整数.toString(计数),25160)代码>都给了我JAVA中的错误(语法错误)。请给我一些建议。多谢各位~
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.InputAdapter;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Prac1 extends ApplicationAdapter {
private float w,h,tw,th =0;
private OrthographicCamera camera;
private SpriteBatch batch;
private Sprite img;
private int count;
@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 Sprite(new Texture(Gdx.files.internal("iceCream.png")));
tw = img.getWidth();
th = img.getHeight();
img.setBounds(camera.position.x - (tw/2), camera.position.y - (th/2),tw,th);
count=0;
Gdx.input.setInputProcessor(new InputAdapter(){
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(img.getBoundingRectangle().contains(screenX, screenY) && count<=31)
System.out.println(count++);
return true;
}
});
}
@Override
public void render () {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
img.draw(batch);
batch.end();
}
}
package com.mygdx.game;
导入com.badlogic.gdx.ApplicationAdapter;
导入com.badlogic.gdx.gdx;
导入com.badlogic.gdx.InputAdapter;
导入com.badlogic.gdx.graphics.GL20;
导入com.badlogic.gdx.graphics.Orthographic Camera;
导入com.badlogic.gdx.graphics.Texture;
导入com.badlogic.gdx.graphics.g2d.Sprite;
导入com.badlogic.gdx.graphics.g2d.SpriteBatch;
公共类Prac1扩展应用程序适配器{
专用浮点数w,h,tw,th=0;
私人正交摄影机;
专用SpriteBatch批次;
私人精灵img;
私人整数计数;
@凌驾
公共void创建(){
w=Gdx.graphics.getWidth();
h=Gdx.graphics.getHeight();
摄像机=新的正交摄像机(w,h);
摄像机位置设置(w/2,h/2,0);
camera.update();
批次=新的SpriteBatch();
img=新精灵(新纹理(Gdx.files.internal(“iceCream.png”));
tw=img.getWidth();
th=img.getHeight();
图像立根(相机位置x-(tw/2),相机位置y-(th/2),tw,th);
计数=0;
setInputProcessor(新的InputAdapter(){
@凌驾
公共布尔接地(整数屏幕X、整数屏幕Y、整数指针、整数按钮){
如果(img.getBoundingRectangle().contains(screenX,screenY)&&count您需要声明位图字体并在您的创建方法中初始化它(看起来您忘记了这么做):
替换
System.out.println(count++);
使用count++
时,您需要声明位图字体,并在创建方法中对其进行初始化(看起来您忘记了这么做):
替换
System.out.println(count++);
使用count++
当你说它不起作用时,你是什么意思?计数只是不显示还是根本不编译?哦,是的,它缺少信息,是语法错误。你知道变量count
是如何显示在屏幕上的吗?当你说它不起作用时,你的意思是什么?计数只是不显示还是不起作用根本不编译?哦,是的,是缺少信息,是语法错误。你知道变量count
是如何显示在屏幕上的吗?