开发者

Touch event not working

开发者 https://www.devze.com 2023-02-17 03:49 出处:网络
I am implementing a game which is having touch events and I have implemented that but not working. Here is my code for touch listener:

I am implementing a game which is having touch events and I have implemented that but not working. Here is my code for touch listener:

public boolean onTouch(View v, MotionEvent event) {

    int action = event.getAction();
    if开发者_JAVA百科(action == MotionEvent.ACTION_DOWN)
    {
        if(event.getX()> r.x && event.getX()< (r.x +100) && event.getY()>(r.y-20) && event.getY()<r.y)
        {
            touch = true;
        }
        return true;
    }
    else if(action == MotionEvent.ACTION_MOVE && touch)
    {
        if(event.getX()>0 && event.getX()<220)
        {
            r.x = event.getX();
            r.y = event.getY();
        }
        return true;

    }

    return false;

}

here r is the object of rectangle and x and y are the coordinates of rectangle.


i am writing the touch listener in surfaceview so i have written the listener in activity hence problwm solved

0

精彩评论

暂无评论...
验证码 换一张
取 消