2013-08-21 70 views
0

即時通訊新手。我試圖創建一個簡單的遊戲,當我遇到一個問題時,我還沒有找到任何解決方案。我一直試圖展示的png根本沒有顯示,沒有錯誤或任何東西。而且我把它放在屏幕的中間,所以它不在繪圖空間之外。libGdx繪製方法不顯示PNG

我想事先感謝您的答案。 繼承人我的代碼:

public class Kurve implements ApplicationListener { 
Texture left; 
Texture right; 
private OrthographicCamera camera; 
private SpriteBatch batch; 
ShapeRenderer sr; 
float w; 
float h; 
float circleX; 
float circleY; 
Circle c; 

@Override 
public void create() { 
    w = Gdx.graphics.getWidth(); 
    h = Gdx.graphics.getHeight(); 
    sr = new ShapeRenderer(); 
    camera = new OrthographicCamera(1, h/w); 
    batch = new SpriteBatch(); 
    left = new Texture(Gdx.files.internal("key_left.png")); 
    right = new Texture(Gdx.files.internal("key_right.png")); 
    circleX = w/2; 
    circleY = 0; 
    c = new Circle(circleX, circleY, 5); 
    Rectangle leftKey = new Rectangle(0, h/2, 64, 64); 
    Rectangle rightKey = new Rectangle(w - 64, h/2, 64, 64); 

} 

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

@Override 
public void render() { 
    Gdx.gl.glClearColor(1, 1, 1, 1); 
    Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); 
    if (circleY >= h) { 
     circleY = 0; 
    } 
    batch.setProjectionMatrix(camera.combined); 

    batch.begin(); 
    batch.draw(left, 10, 10); 
    batch.draw(right, h/2, w/2); 
    batch.end(); 

    sr.begin(ShapeType.Filled); 
    sr.setColor(1, 0, 0, .3f); 
    sr.circle(w/2, circleY += 1, 5); 
    c.set(w/2, circleY += 1, 5); 
    sr.end(); 

} 

@Override 
public void resize(int width, int height) { 
} 

@Override 
public void pause() { 
} 

@Override 
public void resume() { 
} 

}

回答

1

的問題大概是這樣的

camera = new OrthographicCamera(1, h/w); 

你有1px的寬,大概就像9/16高規模的渲染區域。因此大致爲1px * 1px的屏幕尺寸。如果您在(10,10)處繪製已經超出渲染區域的左側紋理。

這樣來做:

camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
+0

哇真棒,我是一個總的小白,從來沒有想到這一點。非常感謝!我不太瞭解相機,所以它永遠不會讓我知道爲什麼圈子即時繪圖實際上是繪製:(再次感謝! – user2685747