我一直在努力從http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/的例子在這個我想做一些改變。如何將圖像從下往上連續移動?
Speed.java
public class Speed {
public static final int DIRECTION_RIGHT = 1;
public static final int DIRECTION_LEFT = -1;
public static final int DIRECTION_UP = -1;
public static final int DIRECTION_DOWN = 1;
private float xv = 1; // velocity value on the X axis
private float yv = 1; // velocity value on the Y axis
private int xDirection = DIRECTION_RIGHT;
private int yDirection = DIRECTION_DOWN;
public Speed() {
this.xv = 1;
this.yv = 1;
}
public Speed(float xv, float yv) {
this.xv = xv;
this.yv = yv;
}
public float getXv() {
return xv;
}
public void setXv(float xv) {
this.xv = xv;
}
public float getYv() {
return yv;
}
public void setYv(float yv) {
this.yv = yv;
}
public int getxDirection() {
return xDirection;
}
public void setxDirection(int xDirection) {
this.xDirection = xDirection;
}
public int getyDirection() {
return yDirection;
}
public void setyDirection(int yDirection) {
this.yDirection = yDirection;
}
// changes the direction on the X axis
public void toggleXDirection() {
xDirection = xDirection * -1;
}
// changes the direction on the Y axis
public void toggleYDirection() {
yDirection = yDirection * -1;
}
}
利用這一點,在各個方向上的圖像移動。現在我只想限制這個從底部到頂部的運動。 onclick的功能是,我們可以點擊並拖動圖像到需要的位置。我想用圖像消失或去其他活動來取代它。請幫助我對此代碼進行更改。提前致謝。
我也想知道...請幫忙... – ALi
用'private float xv = 0;'替換'private float xv = 1;'? –
@SherifelKhatib沒有解決問題。 –