我想在使用libGDX遊戲引擎的android項目中反彈球。如何使用libGDx項目反彈球
ball = new Texture("football.jpg");
batch = new SpriteBatch();
sprite = new Sprite(ball);
render(float delta)
{
batch.begin();
sprite.draw(batch);
batch.end();
stage.draw();
jumpUp(); //here i call the jump function..
}
跳轉功能如下:
public void jumpUp()
{
sprite.setY(sprite.getY()+2);
dem=sprite.getY();
if(dem==100.0f)
{
jumpDown();
}
}
public void jumpDown()
{
sprite.setY(sprite.getY()-1);
}
球實際上是向上移動,但它沒有再下來。 還應該在render()
方法中調用jumpDown()
?
這是不是導致'Ball',99和101之間來回跳躍,asthe方向總是反轉,如果pos = 100!? – Springrbua 2015-03-03 10:14:44
哎呀,你是對的。我想寫<0.感謝您的領導。 – Nessuno 2015-03-03 10:16:26
是的,我認爲是這樣xD無論如何,這是一個很好的答案,+1 – Springrbua 2015-03-03 12:30:00