2014-10-03 3 views
0

어떻게 fitviewport 또는 뷰포트를 사용할 수 있습니까? 나는 많은 안드로이드 장치에 화면을 맞출 필요가있다. 나는 당신이 나를 위해 몇 가지 코드를 붙여 넣을 수 있다면 나는 그것을 aprecciate, 당신의 도움을 주셔서 감사합니다, 어떻게을 사용하는 아이디어를 가지고 있겠지 ...libGDX ViewPort Android 기기

public void show(){ 
    batch = main.getBatch(); 
    texture = new Texture(Gdx.files.internal("spacebg.png")); 
    Texture texturaBola = new Texture(Gdx.files.internal("bola.png")); 
    ball = new Ball(Gdx.graphics.getWidth()/2 - texturaBola.getWidth()/2, Gdx.graphics.getHeight()/2 - texturaBola.getHeight()/2); 
    Texture texturaPala= new Texture(Gdx.files.internal("pala.png")); 
    Lpaddle = new LeftPaddle(80, Gdx.graphics.getHeight()/2 -texturaPala.getHeight() /2); 
    Rpaddle = new RightPaddle(Gdx.graphics.getWidth() -100, Gdx.graphics.getHeight()/2 - texturaPala.getHeight() /2, ball); 
    font = new BitmapFont(); 
    font.setColor(Color.WHITE); 
    font.setScale(1f); 
    puntuacion = 0; 

} 
public void render(float delta){ 
    Gdx.gl.glClearColor(0, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    updatePuntuacion(); 
    Lpaddle.update(); 
    Rpaddle.update(); 
    ball.update(Lpaddle, Rpaddle); 
    batch.begin(); 
    batch.draw(texture, 0, 0,texture.getWidth(), texture.getHeight()); 
    ball.draw(batch); 
    Lpaddle.draw(batch); 
    Rpaddle.draw(batch); 
    font.draw(batch, "Points: " + Integer.toString(puntuacion), Gdx.graphics.getWidth()/4 ,Gdx.graphics.getHeight() - 5); 
    font.draw(batch, "High score: " + Integer.toString(puntuacionMaxima),Gdx.graphics.getWidth() - Gdx.graphics.getWidth()/4 ,Gdx.graphics.getHeight() - 5); 
    batch.end(); 
} 

private void updatePuntuacion(){ 
    if(ball.getBordes().overlaps(Lpaddle.getBordes())) { 
     puntuacion = puntuacion + 1; 
     if(puntuacion > puntuacionMaxima) 
     puntuacionMaxima = puntuacion; 

    } 
    if(ball.getBordes().x <= 0) 
     sonidoex.play(); 

    if(ball.getBordes().x <= 0) 
    puntuacion =0; 

    if(ball.getBordes().x <=0) 
     Gdx.input.vibrate(1000); 

    if(ball.getBordes().x <=0) 
     Screens.juego.setScreen(Screens.MAINSCREEN); 

    ball.comprobarPosicionBola(); 
    } 
public void hide(){ 
    font.dispose(); 
    texture.dispose(); 
} 

@Override 
public void dispose(){ 
    preferencias.putInteger("puntuacionMaxima", puntuacionMaxima); 
    preferencias.flush(); 
} 

public void resize(int width, int height){  
    float widthImage = texture.getWidth(); 
    float heightImage = texture.getHeight(); 
    float r = heightImage/widthImage; 
    if(heightImage > height) { 
     heightImage = height; 
     widthImage = heightImage/r; 
    } 
    if(widthImage > width) { 
     widthImage = width; 
     heightImage = widthImage * r; 
    } 
    escala = width/widthImage; 

} 
+0

문서를 읽으셨습니까? http://developer.android.com/guide/webapps/targeting.html – dave

+1

wiki가 도움이 될 것입니다 : https://github.com/libgdx/libgdx/wiki/Viewports – Springrbua

답변

0
+0

이해할 수 없습니다 :/좀 더 구체적으로 표현해주십시오. ? – JAnoob92

+0

어디에서 더 구체적으로 말하고 싶습니까? 뷰포트에 대한 문서를 제공 했으므로 필요한 모든 작업을 수행 할 수 있습니다. 예제에서 중요한 코드를 복사하여 붙여 넣으면 완료됩니다. –