私は船がエンティティを拡張するEntityとShipの2つのクラスを持っています。私のエンティティクラスで私はプライベートフィールドスピードを持っています。私の船級クラスでは、現在のスピード+加速時間にデルタタイムと言ってスピードを上げようとするアップデート方法があります。ここでJava - スーパークラスのフィールドが正しく変更されていません
は、Entityです:
private float height, rotation, speed, width;
private Sprite sprite;
private Vector2 origin, position;
public Entity (float x, float y) { position = new Vector2 (x, y); }
public Entity (float x, float y, Texture texture)
{
this (x, y);
if (texture != null)
{
sprite = new Sprite (texture);
width = sprite.getWidth();
height = sprite.getHeight();
origin = new Vector2 (x + width/2f, y + height/2f);
}
else
{
sprite = null;
origin = position;
}
}
public Entity (float x, float y, float rotation, Texture texture)
{
this (x, y, texture);
this.rotation = rotation;
}
public Entity (float x, float y, float rotation, float speed, Texture texture)
{
this (x, y, rotation, texture);
this.speed = speed;
}
public float getHeight() { return height; }
public float getRotation() { return rotation; }
public float getSpeed() { return speed; }
public float getWidth() { return width; }
public float getX() { return position.x; }
public float getY() { return position.y; }
public void setPosition (Vector2 vector) { position = vector; }
public void setRotation (float value) { rotation = value; }
public void setSpeed (float value) { speed = value; }
public void setSprite (Sprite sprite) { this.sprite = sprite; }
public void setX (float value) { position.x = value; }
public void setY (float value) { position.y = value; }
public Sprite getSprite() { return sprite; }
public Vector2 getOrigin() { return origin; }
public Vector2 getPosition() { return position; }
そして、ここでは船のupdate()
方法である:私は起こることを期待何
setSpeed (getSpeed() + acceleration * delta);
System.out.println (getSpeed());
その速度はどのような加速*デルタである増加しています。しかし、速度はその値と同じに設定され、増分されません。エンティティのフィールドを静的に設定すると、コードは機能しますが、私はそれをしてはいけないと感じています。私はフィールドをprotectedに設定しようとしましたが、Entityクラスはabstractにしましたが、私はまだ同じ効果を得ています。フィールドを静的に設定しない限り、私が間違っていることは本当に失われていますか?
EDIT: Shipの更新方法全体。
public void update (float delta)
{
// Updating the origin's position
getOrigin().set (getX() + getWidth()/2f, getY() + getHeight()/2f);
updateTurrets (delta);
updateBullets (delta);
setSprite (updateSprite (delta));
//calculateRotateTo (moveTo);
setRotation (0f);
rotateTo = getRotation();
if (getRotation() != rotateTo)
{
setRotation (rotateTo);
}
else if (getOrigin() != moveTo)
{
/*float currDistance = Utils.calculateDistance (originalPos, getOrigin());
float totDistance = Utils.calculateDistance (originalPos, moveTo);
if (currDistance >= totDistance/2f)
accelerating = false;
else
accelerating = true;
if (accelerating)
setSpeed (getSpeed() + acceleration * delta);
else
{
if (getSpeed() > 0f)
setSpeed (getSpeed() - acceleration * delta);
else
{
setSpeed (0f);
setPosition (moveTo);
}
}*/
setSpeed (getSpeed() + acceleration * delta);
System.out.println (getSpeed());
}
}
EDIT#2:私はいくつかの余分なテストを行なったし、私はメインのrender()メソッドでは、船のインスタンスを置けばLibGDXはそれが動作与えること。しかし、それ以外の場所では、そうではありません。
アクセラレーションまたはデルタのいずれかがゼロですか? Javaの優先順位ルールを思い出してください。 – Mordechai
いいえ、デルタはほとんどゼロですが、正確にゼロではありません。 –
どのようなタイプですか?浮く?どちらも? – Mordechai