試圖製作一個簡單的答題器,顯示隨每次點擊/點擊而增加的數字。 該計數器工作正常,但我不能讓它顯示一個數字,每次點擊更新。 System.out.print打印計數器正在工作,但font.draw不會隨每個水龍頭更新。不知道現在該做什麼。如何使String.draw在字符串更新時更新[LibGDX]
package com.me.mygdxgame;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
public class MyGdxGame implements ApplicationListener {
SpriteBatch batch;
BitmapFont font;
Texture mario;
int cash = 0;
String money = String.valueOf(cash);
Vector2 position;
public boolean touchDown(int x, int y, int pointer, int button) {
if (button == Input.Buttons.LEFT) {
System.out.println("Test");
return true;
}
return true;
}
@Override
public void create() {
mario = new Texture(Gdx.files.internal("data/mario.jpeg"));
batch = new SpriteBatch();
font = new BitmapFont();
position = new Vector2(150, 150);
}
@Override
public void dispose() {
batch.dispose();
font.dispose();
}
@Override
public void render() {
if(Gdx.input.justTouched()){
cash++;
System.out.println("e");
System.out.println(cash);
}
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
font.draw(batch, money, 300, 260);
batch.end();
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
}
現金!=錢... –
哼,從來不得不用「String money = String.valueOf(cash);」不知道它是如何工作的。你會如何建議讓「現金」成爲可打印的字符串? – CodingNub