2016-11-30 10 views
0

Ich möchte Karte Sprites mit benutzerdefinierten Einheiten zu rendern. 1 world unit = 1 card Breite, like is done here
Aber das Sprite wird nicht gerendert. Das hat vorher funktioniert, aber ich frage mich, warum es nicht jetzt ist. Es macht nur einen leeren Bildschirm.libgdx Sprite plötzlich nicht rendern, mit benutzerdefinierten Welteinheiten

import com.badlogic.gdx.ApplicationAdapter; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.graphics.OrthographicCamera; 
import com.badlogic.gdx.graphics.g2d.Sprite; 
import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
import com.badlogic.gdx.graphics.g2d.TextureAtlas; 

public class MyGame extends ApplicationAdapter { 
    SpriteBatch batch; 
    Sprite sprite; 
    TextureAtlas atlas; 
    OrthographicCamera cam; 
    float CARDWITH=1f;//chosen as our world unit 
    float CARDHEIGHT=108f/76f; 
    float MINIMUM_VIEWPORT_SIZE=10f;//our viewport is 10 card widths wide 
    @Override 
    public void create() { 
     batch = new SpriteBatch(); 
     atlas=new TextureAtlas(Gdx.files.internal("cardspack.atlas")); 
     sprite=atlas.createSprite("c2"); 
     sprite.setSize(CARDWITH,CARDHEIGHT);//make 1 unit of our world equal to 1 card width. 
     cam=new OrthographicCamera(); 
    } 

    @Override 
    public void resize(int width, int height) { 
     if(width>height){ 
      cam.viewportHeight=MINIMUM_VIEWPORT_SIZE; 
      cam.viewportWidth=cam.viewportHeight*(float)width/(float)height; 
     } 
     else { 
      cam.viewportWidth=MINIMUM_VIEWPORT_SIZE; 
      cam.viewportHeight=cam.viewportWidth*(float)height/(float)width; 
     } 
     cam.update(); 
    } 

    @Override 
    public void render() { 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
     batch.begin(); 
     sprite.draw(batch); 
     batch.end(); 
    } 

    @Override 
    public void dispose() { 
     batch.dispose(); 
    } 
} 

Here is the texture atlas cardspack.atlas hier ist ein link to the image of cardspack

Antwort

0

wird Ihre Karte angezeigt (bei 0, 0 coords), aber es ist zu klein:

float CARDWITH = 1f;//chosen as our world unit 
float CARDHEIGHT = 108f/76f; 

, wenn Sie diese Zeile aus kommentieren:

//sprite.setSize(CARDWITH, CARDHEIGHT);//make 1 unit of our world equal to 1 card width. 

dann sehen Sie es

0

Oh, dumm von mir, ich war die Kamera nicht mit render(), so dass die Einheiten nicht Wirksam wurden

void render(){ 
batch.setprojectionmatrix(cam.combined); 
.. 
} 
Verwandte Themen