私はアプリを作成していて、ある程度は機能していますが、ありがたいことに、自分の問題が何であるかを知っています。境界線の周りを移動するスプライトがあり、スプライトが特定の場所でボールを発射するようにします。現在、私のアプリはボールを位置 (0,0) に表示し、想定されているときにボールを撃ちます。これは、更新メソッドで x に 10 を追加することで行われるため、アニメーションになります。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
}
アイデアや提案はありますか?間違ったタイミングでボールを表示しているだけで、これを修正する必要があります。エラーか何かに違いない。