我正在制作一个应用程序,我有点工作,但谢天谢地我知道我的问题是什么。我有一个围绕边界移动的精灵,我希望精灵在特定的位置射球。目前,我的应用程序将球显示在位置(0,0),然后在应该的时候将其射出。它通过在更新方法中添加10到x来实现这一点,因此它是一个动画,我可以通过更改10来加快它的速度。变量x和y的默认值为0.我比上面指定的更改它们。我希望他们默认保持0,但我不希望球在移动之前显示。现在它在启动时显示球,然后移动。一旦我给出x和y值,我希望它显示球。
以下是当前代码的摘要。
// This moves the ball down the right side of screen
if (x > ov.getWidth() - width - xSpeed){
xSpeed = 0;
ySpeed = 10;
direction = 1;
shootL(); // shoots the ball left towards the left side of screen
}
// moves ball up the screen on left side
if (x + xSpeed < 0){
x = 0;
xSpeed = 0;
ySpeed = -10;
direction = 3;
shootR(); // shoots the ball towards right side of screen
}
private void shootR() {
// TODO Auto-generated method stub
// need to manipulate variable q to go across screen
q += 10;
// eventually manipulate r so that it shoots at the right spot on screen, not my major problem right now.
}
private void shootL() {
// TODO Auto-generated method stub
// need to manipulate variable q to go across screen
q += -10;
// eventually manipulate r so that it shoots at the right spot on screen, not my major problem right now.
}
public void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
update();
int srcY = direction * height;
Rect src = new Rect (0, srcY, width, srcY + height);
Rect dst = new Rect (x, y, x+width, y+height);
canvas.drawBitmap(b, src, dst, null); // draws sprite around border
Paint p = new Paint();
canvas.drawBitmap(fire, q, r, p); // draws ball that shoots across
}
任何人有任何想法或建议吗?它只是在错误的时间显示球,我需要解决这个问题。必须是错误或其他什么。
答案 0 :(得分:0)
在我改变之前,我正在画画。您需要更改变量,然后绘制!