1. Are you ready for the Galaxy S20? Here is everything we know so far!

detecting swiping direction

Discussion in 'Android Development' started by osos2323, Apr 7, 2020.

?

moving player right or left depending on swiping

  1. true

    0 vote(s)
    0.0%
  2. false

    0 vote(s)
    0.0%
  1. osos2323

    osos2323 Lurker
    Thread Starter

    Hi;
    In my Player.java class, I want to incorporate a function that moves my player according to the left or right swipes. I also used time in seconds in order to vary the movement in an cyclic way:






    class MyGestureDetector extends SimpleOnGestureListener {
    @override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT-4:00"));
    Date currentLocalTime = cal.getTime();
    DateFormat date = new SimpleDateFormat("KK:mm");
    date.setTimeZone(TimeZone.getTimeZone("GMT-4:00"));
    String localTime = date.format(currentLocalTime);
    try {
    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
    return false;
    // right to left swipe
    if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
    X-=K;
    int currentSeconds = cal.get(Calendar.SECOND);
    Y=Y*Math.cos(18.currentSeconds);
    } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
    X+=K;
    int currentSeconds = cal.get(Calendar.SECOND);
    Y=Y*Math.cos(18.currentSeconds);
    }
    } catch (Exception e) {
    // nothing
    }
    return false;
    }
    '''






    After some research, this is the class I included in player.java. So my question is: Is there a more efficient way to detect swiping directions(without creating any additional class) and what is your opinion about the code structure knowing that the objective is to change X according to swipe direction.

    Thank you.
     


  2. Unforgiven

    Unforgiven ...eschew obfuscation...
    Moderator

    Development thread moved to the dev area for better exposure. :)
     
Loading...

Share This Page

Loading...