如何从底部移动图像连续顶? [英] How to move images from bottom to top continuously?
问题描述
我一直在工作的例子,从<一个href="http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/">http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/在此我想做出一些改变。
I've been working on the example from http://obviam.net/index.php/a-very-basic-the-game-loop-for-android/ In this I want to make few changes.
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的功能,我们可以单击并拖动图片到所需的位置。我想替换只有使图像消失或转到其他活动。请帮我在更改此code。先谢谢了。
Using this, the image moves in all directions. Now I just want to limit this movement from bottom to top. And the functionality for onclick is that, we can click and drag the image to required position. I want to replace that with just make the image to disappear or go to another activity. Please help me in making changes to this code. Thanks in advance.
推荐答案
如果你已经使用SurfaceView然后在的OnDraw(帆布油画)
方法code是从下到上的运动图像是这样的。
if you have used SurfaceView then in onDraw(Canvas canvas)
method the code is for moving image from bottom to top is something like this.
canvas.drawBitmap(bitmap,xPoint,yPoint,paint);
其中,位图图像,XPOINT是(位图,你要移动)x坐标,yPoint是Y坐标和涂料是涂料,这也是可以为空。
where bitmap is an image(Bitmap which you want to move),xPoint is the x coordinate,yPoint is the y coordinate and paint is a Paint which is also can be null.
和从下到上的运动刚刚更新
and for bottom to top movement just update
yPoint = yPoint - 1;
在之前的OnDraw任何线程()
电话。
愿这帮助你。
这篇关于如何从底部移动图像连续顶?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!