Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让我的程序在Android中等待TouchEvent_Android - Fatal编程技术网

如何让我的程序在Android中等待TouchEvent

如何让我的程序在Android中等待TouchEvent,android,Android,我面临一个问题。我已经写下了选择白色球的代码,现在我想让我的程序等待屏幕上的另一次触摸 在这一行之后WhiteBall.ball.getPaint().setColor(Color.BLUE) 现在球被选中了,我想让我的程序等待另一次触球,这将定义球的速度,我如何让我的程序等待触球 public boolean onTouchEvent(MotionEvent e) { int xpos=(int) e.getX(); int ypos=(int) e.getY();

我面临一个问题。我已经写下了选择白色球的代码,现在我想让我的程序等待屏幕上的另一次触摸

在这一行之后
WhiteBall.ball.getPaint().setColor(Color.BLUE)

现在球被选中了,我想让我的程序等待另一次触球,这将定义球的速度,我如何让我的程序等待触球

public boolean onTouchEvent(MotionEvent e)
{
    int xpos=(int) e.getX();
    int ypos=(int) e.getY();

    if(WhiteBall.velocity==0)
        if((xpos>WhiteBall.x-30 && xpos<WhiteBall.x+30) && (ypos>WhiteBall.y-30 && ypos<WhiteBall.y+30)) {
            WhiteBall.ball.getPaint().setColor(Color.BLUE);


           //  WhiteBall.speed(6);

        }

    Log.d("OnTouchPosition X",""+xpos);
    Log.d("OnTouchPosition Y",""+ypos);
    return true;
}
public boolean onTouchEvent(运动事件e)
{
int xpos=(int)e.getX();
int ypos=(int)e.getY();
if(WhiteBall.velocity==0)

如果每次触摸((xpos>WhiteBall.x-30&&xposWhiteBall.y-30&&ypos),根据触摸的元素,您应该设置一个变量。例如,在代码中:

if (this.color == null) {
  this.color = Color.BLUE;
}
当触摸到另一个“物体”时,设置速度:

else {
    this.velocity = 6;
    WhiteBall.ball.getPaint().setColor(this.color);
    WhiteBall.ball.setSpeed(this.velocity);
}

在每次触摸中,根据触摸的元素,您应该设置一个变量。例如,在代码中:

if (this.color == null) {
  this.color = Color.BLUE;
}
当触摸到另一个“物体”时,设置速度:

else {
    this.velocity = 6;
    WhiteBall.ball.getPaint().setColor(this.color);
    WhiteBall.ball.setSpeed(this.velocity);
}