简体   繁体   中英

Scrolling text in libgdx java

I am trying to get text to slowly print one character within a string at a time so the text appears to be printed out and scrolling. I can't seem to find where the answer lies. Here is what I have tried

public void render(SpriteBatch batch) {
    for(int i = 0; i < text.length(); i++){
        e += Gdx.graphics.getDeltaTime();
        if(e > 5f){
            System.out.println(e);
            tmp+= text.substring(i, i+1);
            glyph.setText(font, tmp);
            font.draw(batch, glyph, 100 + glyph.width, 100);
            e = 0;
            i++;
            continue;
        }
    }
}

However the text just zooms off the screen. Any help in accomplishing the smooth one character at a time printing is extremely appreciated!

您需要在绘图调用100 + glyph.width删除该行,它可以完美地工作

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM