android - How can I write different texts after each interval? -
i want write different texts after intervals. wrote codes not working
@override public void render() { gdx.gl.glclearcolor(1,1,1,1); gdx.gl.glclear(gl10.gl_color_buffer_bit); float delay = 5; // seconds timer.schedule(new task(){ @override public void run() { batch.begin(); font.draw(batch, texts[flag],200, 200); batch.end(); } }, delay,5); }
it great if me figuring out doing wrong explanation.
you not using things correctly. render()
called every gameloop (about 60 times per second, depending on fps). schedule new timertask
60 times per second... draw()
inside timertask
, if timer
event fired. see white screen, because telling screen
overdraw himself white color every render loop:
gdx.gl.glclearcolor(1,1,1,1); gdx.gl.glclear(gl10.gl_color_buffer_bit);
note, color(1, 1, 1, 1)
white full opacity.
what should instead is:
in show()
, if screen class or in create
, if applicationlistener
/game
class add this:
float delay = 5; // seconds text = "this 1. text"; // text member variable (string) nb = 1; // nb member variable (int) timer.schedule(new task(){ @override public void run() { nb++; text = "this " + nb + ". text"; } }, delay, 5);
this changes text every 5 seconds, "this 1. text" "this 2. text" ...
in render need draw() it:
public void render() { gdx.gl.glclearcolor(1,1,1,1); gdx.gl.glclear(gl10.gl_color_buffer_bit); batch.begin(); font.draw(batch, text, 200, 200); batch.end(); }
this should work. suggest read tutorials libgdx , how use gameloop.
Comments
Post a Comment