假設您使用輪詢進行輸入,您需要爲空格鍵的update
方法添加支票。如果空格鍵被按下,則將新實例Bullet
添加到子彈數組中,並在構造函數中傳遞初始的x
,y
和velocity
。
你Bullet
類可能看起來像:
public class Bullet
{
public static float VELOCITY;
private Vector2f position;
public Bullet(float x, float y, float velocity)
{
position = new Vector2f(x, y);
VELOCITY = velocity;
}
public void update(float delta, boolean vertical)
{
if(vertical)
{
y += VELOCITY * delta;
}
else
{
x += VELOCITY * delta;
}
}
}
你也想呼籲bulelts更新方法在update
方法。喜歡的東西做到這一點:
for(Bullet bullet : bullets)
{
bullet.update(delta, true);
}
雖然很可能會有人能回答你的問題(我還沒有和引擎工作),我建議先得到Java的把握 - 通過一些[教程](HTTP: //docs.oracle.com/javase/tutorial/)。 –
尋找其他人的幫助可能對你有用,但最好學會如何自己做,這樣你就可以完全理解這些概念。 – syb0rg