Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Good day, I have been coding for quite a while now and I'm at an certain point where i am having difficulties on solving something. I've been creating a preview screen which contains the following:

  1. reads .txt file and stores them in an array which will be displayed on the screen.
  2. the text will have an animation which will be moving upwards like a starwars type of intro.
  3. the background of screen will also move upwards.

the problem that I have encountered are the following:

  • my text did not fit on the screen, but i did try to change the font and the font size and also did change the spacing in the .txt file.
  • the text always starts in the middle of the screen which it should start at the bottom of the screen.
  • the background is buggy, tried to debug it but still can find a solution for a parallaxbackground(scrolling background)

and here is the code.

public class PreviewScreen implements Screen {

private static DugManMainClass game;
private SpriteBatch batch;
private OrthographicCamera camera;
private Texture tx1 = Assets.bgmenu;
private BitmapFont font = Assets.menufont2;
private final static List<String> lines = new ArrayList<String>(); 
private static int time = 0;
private float temp = 0;
private Sprite s;


public PreviewScreen(DugManMainClass game) {

    this.game = game;

    //reads .txt file and stores them in an array

    try
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(Gdx.files.internal("previewtext.txt").read()));
        String line = "";
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }
        br.close();
    } 
    catch(Exception e)
    {
        e.printStackTrace();
    }


}


@Override
public void render(float delta) {


    float w = s.getHeight();

    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

            //temp is a timer which will do the animation effect for the text and background
    temp += Gdx.graphics.getDeltaTime();


    while(temp>1.0f/60.0f)
    {
        PreviewScreen.tick();
        temp -=1.0f/60.0f;

    //here is my problem for the background

    s.setU(temp+1f);
    s.setU2(temp+1f);

    }





    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    s.draw(batch);

// i commented this out because i waited to draw my sprite which is the background text(parallaxbackground) // batch.draw(s, 0, -(temp / 10 % w)); // batch.draw(s, 0, -(temp / 10 % w) + w);

    int yo = time / 4;


    //this is where the the text problem is
    for (int y = 0; y <= 420 / 12; y++) 
    {
        int yl = yo / 12 + 420 / 12 - y;
        if (yl >= 0 && yl < lines.size()) 
        {
            font.draw(batch,lines.get(yl), (800 - 30 * 12) / 2,  y * 12 + yo % 12);

        }
    }

    batch.end();

    // TODO Auto-generated method stub

}

@Override
public void resize(int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void show() {

    batch = new SpriteBatch();

    float w = 800;
    float h = 420;

    camera = new OrthographicCamera();
    camera.setToOrtho(false, w, h);

    tx1.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);

    s = new Sprite(tx1);
    s.setPosition(0, 0);


    Assets.bgsound3.play(1f);
    // TODO Auto-generated method stub

}


@Override
public void dispose() {

    Assets.dispose();
    // TODO Auto-generated method stub

}

public static void tick() {
    time++;

    if (Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isTouched()) {
        game.setScreen(new MainMenuScreen(game));
        Assets.bgsound3.stop();
    }

    if (time / 4 > lines.size() * 10 + 250) {


        game.setScreen(new MainMenuScreen(game));
        Assets.bgsound3.stop();
    }

}

}

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.