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.

I'm using this code to set a 800x420 image to be full screen:

public void show() {
    float w = Gdx.graphics.getWidth();
    float h = Gdx.graphics.getHeight();
    camera = new OrthographicCamera(1, h / w);
    batch = new SpriteBatch();
    texture = new Texture(Gdx.files.internal("images/splashatlas/splashatlas1.png"));
    texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
    TextureRegion region =
    new TextureRegion(texture, 0, 0, 800, 420);
    sprite = new Sprite(region);
    sprite.setSize(0.9f,
            0.9f * sprite.getHeight() / sprite.getWidth() );
            sprite.setOrigin(sprite.getWidth() / 2,
            sprite.getHeight() / 2);
            sprite.setPosition(-sprite.getWidth() / 2,
            -sprite.getHeight() / 2);
}


public void render(float delta) {
    Gdx.gl.glClearColor( 1f, 1f, 1f, 1f );
    Gdx.gl.glClear( GL20.GL_COLOR_BUFFER_BIT );
    batch.setProjectionMatrix(camera.combined);
    batch.begin();
    sprite.draw(batch);
    batch.end();
}

But on real device it looks like this:

On a real device

I tried to setSize with different parameters:

    sprite.setSize(1.0f,
            1.0f  );

Now it's fullscreen, but it's really stretched:

fullscreen, but stretched

What is the way to set a background to be full screen? I want it to look like this:

what I want

share|improve this question
    
change new TextureRegion(texture, 0, 0, 800, 420); to new TextureRegion(texture, 0, 0, w, h); –  Thebluefish Mar 1 at 13:03
    
this gives me a white screen. –  Opetmar Mar 1 at 13:06
    
this zoom the picture too much ... its looks blue now –  Opetmar Mar 1 at 13:13
    
i updated the question .. –  Opetmar Mar 1 at 13:14
    
ah ok, I had a chance to look at the documentation. try sprite.setSize(1.0f, 1.0f); –  Thebluefish Mar 1 at 13:18

2 Answers 2

up vote 1 down vote accepted

the problem was in my images size , i set the viewport to be 800x480 but the images size was 800x420 , i just changed the images size to 800x480 and in setSize() i changed it like the following :

sprite.setSize(1f,
            1f * sprite.getHeight() / sprite.getWidth() );

and its work perfectly now.

share|improve this answer
    
Consider using Gdx.graphics.getWidth() and Gdx.graphics.getHeight() as that will set the sprite to the size of the device's screen, regardless of the PPI. –  user959631 Mar 4 at 17:58
    
this will stretch the screen too much . –  Opetmar Mar 6 at 20:51
    
but anyway the method i used above should scale the splash screen according to the device width and height and regardless of the ppi –  Opetmar Mar 6 at 20:53

In your render() method, you could set Gdx.gl.glClearColor(0, 0, 0, 0); which will set the background of your game to Black

Then you don't need to resize the sprite and the texture won't distort.

Hope this helped.

share|improve this answer
1  
but this method will not give a good results if i decided to change my splash screen to colored sprite because it will be obvious that the splash in not full screen . but anyway thank you I've already solved my problem. –  Opetmar Mar 4 at 12:49
    
Oh, sorry, I wasn't aware that you would want to change the splash screen's color. –  user959631 Mar 4 at 17:57

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.