2017-04-13 20 views
0

ビューポートをステージに設定しようとするたびに、私がシーンに配置したアクタは非常にぼやけて非常に大きくなります。ゲーム世界のサイズを50x100単位の四角形として設定し、すべての単位(スプライト、俳優、ラベル、フォント)をその単位で拡大したいと思います。すべての状態がGAME_SIZE_WIDTH /GAME_SIZE_HEIGHTの寸法を維持するために従っなど私の国家クラスの私はStageを追加し、viewPortを渡したいすべてのStateLibGdxビューポートを理解し、Scene2Dでアロケートします

public abstract class State { 
    public static final float GAME_SIZE_WIDTH = 50 ; 
    public static final float GAME_SIZE_HEIGHT = 100 ; 
    protected OrthographicCamera camera; 

    protected GameStateManager gsm; 
    protected Viewport viewport; 

    public State(GameStateManager gsm) { 
     this.gsm = gsm; 
     camera = new OrthographicCamera(); 
     viewport = new ExtendViewport(GAME_SIZE_WIDTH, GAME_SIZE_HEIGHT, camera); 
     viewport.apply(); 
     camera.position.set(GAME_SIZE_WIDTH/2, GAME_SIZE_HEIGHT/2, 0); 
    } 

    public abstract void handleInput(); 
    public abstract void update(float dt); 
    public abstract void render (SpriteBatch sb); 
    public abstract void dispose(); 
    public abstract void resize(int width, int height) ; 
    } 

を機能をレンダリング提供するクラスの状態を形成inharitateが、アイブ氏は、未調整の背景を(GOTたとえそのフルHD画像の左側に白い枠線が表示されていても、ボタンは調整されていないテキストで表示されます)。

public class MenuState extends State implements InputProcessor { 

private Skin skin; 
private Stage stage; 

private Sprite background; 
private Table table; 
private TextButton startButton,quitButton; 
private Sprite flappyButton; 
private Sprite chodzenieButton; 
private Sprite memoryButton; 
private Sprite rememberSquare; 
private static final String TAG = "kamil"; 
private Vector3 touchPoint; 

public MenuState(GameStateManager gsm) { 
    super(gsm); 

    skin = new Skin(Gdx.files.internal("button/uiskin.json")); 
    stage = new Stage(viewport); 
    table = new Table(); 
    table.setWidth(stage.getWidth()); 
    table.align(Align.center | Align.top); 

    table.setPosition(0,GAME_SIZE_HEIGHT); 
    startButton = new TextButton("New Game",skin); 
    quitButton = new TextButton("Quit Game",skin); 
    startButton.addListener(new ClickListener() { 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      Gdx.app.log("Clicked button","Yep, you did"); 
      event.stop(); 
     } 
    }); 

    table.padTop(5); 
    table.add(startButton).padBottom(5).size(20,10); 
    table.row(); 
    table.add(quitButton).size(20,10); 

    stage.addActor(table); 

    background =new Sprite(new Texture(Gdx.files.internal("backgrounds/bg.jpg"))); 
    background.setSize(GAME_SIZE_WIDTH,GAME_SIZE_HEIGHT); 
    background.setPosition(0,0); 
    touchPoint= new Vector3(); 

    InputMultiplexer im = new InputMultiplexer(stage,this); 
    Gdx.input.setInputProcessor(im); 
    flappyButton=new Sprite(new Texture("menuButton/floopyBirdButtonTexture.png")); 
    chodzenieButton =new Sprite(new Texture("menuButton/swipeMovementsButtonTexture.png")); 
    memoryButton =new Sprite(new Texture("menuButton/memory.png")); 
    rememberSquare = new Sprite(new Texture("menuButton/rememberSquare.png")); 
    rememberSquare.setSize(20,10); 
    flappyButton.setSize(20,10); 
    chodzenieButton.setSize(20,10); 
    memoryButton.setSize(20,10); 
    flappyButton.setPosition(GAME_SIZE_WIDTH/2-flappyButton.getWidth()/2,GAME_SIZE_HEIGHT/2-flappyButton.getHeight()/2); 
    chodzenieButton.setPosition(GAME_SIZE_WIDTH/2-flappyButton.getWidth()/2,flappyButton.getY()- chodzenieButton.getHeight() -2); 
    memoryButton.setPosition(chodzenieButton.getX(),chodzenieButton.getY()- flappyButton.getHeight() -2); 
    rememberSquare.setPosition(flappyButton.getX(),flappyButton.getY()+flappyButton.getHeight()+2); 
} 



@Override 
public void render(SpriteBatch sb) { 
    sb.setProjectionMatrix(camera.combined); 
    sb.begin(); 
    background.draw(sb); 
    flappyButton.draw(sb); 
    chodzenieButton.draw(sb); 
    memoryButton.draw(sb); 
    rememberSquare.draw(sb); 
    sb.end(); 
    stage.act(Gdx.graphics.getDeltaTime()); 
    stage.draw(); 
} 

@Override 
public void dispose() { 
    flappyButton.getTexture().dispose(); 
    chodzenieButton.getTexture().dispose(); 
    background.getTexture().dispose(); 
} 

@Override 
public void resize(int width, int height) { 
    Gdx.app.log("kamil","Resize"); 

    viewport.update(width,height); 
} 
@Override 
public void handleInput() { 
    if(Gdx.input.justTouched()) 
    { 
     // 

    viewport.unproject(touchPoint.set(Gdx.input.getX(),Gdx.input.getY(),0)); 
    if(flappyButton.getBoundingRectangle().contains(touchPoint.x,touchPoint.y)) { 
     gsm.set(new FlopyBirdState(gsm)); 
    } 
     else if (chodzenieButton.getBoundingRectangle().contains(touchPoint.x,touchPoint.y)){ 
     gsm.set(new ChodzenieState(gsm)); 
    } 
    else if (memoryButton.getBoundingRectangle().contains(touchPoint.x,touchPoint.y)){ 
     gsm.set(new MemoryState(gsm)); 
    } 
    else if (rememberSquare.getBoundingRectangle().contains(touchPoint.x,touchPoint.y)){ 
     gsm.set(new FoodEaterState(gsm)); 
    }} 
} 

enter image description here

enter image description here

答えて

1

bluredと非常に大きな:これはあなたが使用しているフォントサイズによるものです。

適切な方法で拡大/縮小されたフォントがある場合は、Bluredを使用しますが、それはあなたまたはビューポートによるものではありません。

世界の幅と高さをビューポートの幅と高さに使用していて、50,100と比べてサイズが大きいスキンからBitmapFontを使用しています。したがって、ビュー幅を画面幅と高さで更新すると、BitmapFontスケールアップすると非常に大きく、ぼやけて見えます。

ソリューション:

  1. 使用しているあなたのBitmapFontを比較することによって、ビューポートのいくつかの大きな世界の幅と高さを使用してください。

  2. BitmapFontのサイズを小さくするか、サイズを大きくしすぎて見栄えが悪くなるように縮小することができます。あなたがTableを使用している

    skin.get("font-name",BitmapFont.class).getData().setScale(.25f); 
    

ので、あなたの俳優は、セル/表にある場合チェックする必要があるかもしれません。あなたは、このフラグでデバッグを有効にすることができstage.setDebugAll(true);

EDIT ExtendViewport が一方向に世界を拡張することにより、世界のアスペクト比黒いバーなしを保つwiki

からあなたはExtendViewportを使用している

、 。世界は最初にビューポート内に収まるようにスケーリングされ、短い方の寸法はビューポートを埋めるように長くなります。

デバイスの幅と高さが400と640であるとしましょう。ビューポートを400と640で更新するとどうなりますか?まず、背景のスプライトの高さをスケーリングし、高さを640に設定します(ビューポートのワールド高さは背景の高さ)が完了しました。背景の幅がSpriteの幅になっているので、幅が高さの半分になり、サイズが640/2 = 320に設定されます。サイズは320台(40 * 2台は両側から白)です。

使用48 * 80(デバイスのほとんどが、この比率である)の代わりに、50 * 100

+0

オーケーあなたのヒントに感謝が、どのように私のゲーム画面の左側と右側の背景マージン(白について1)?どんな解像度の画像を使用していても、私は常に画面の左と右の余白を取得します。私の背景画像のサイズは、(GAMZE_SIZE_WIDTH、GAME_SIZE_HEIGHT)で設定されているので、なぜそれが画面よりも小さいのか分かりません。 – Expiredmind

+0

更新された回答を確認してください – Aryan

+0

最後に私はこれを理解しています。ありがとう! – Expiredmind

関連する問題