Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have a bitmap I'd like to "fling". I'm struggling to get it to fling with ontouchlistener due to it being a bitmap and I'm not sure how to proceed.

To clarify, I don't know how to "fling" the object and what I have doesn't work and I'm asking how to do it for a specific object on the screen rather than the whole screen or an item menu.

Current code Gesture Code:

package com.main.shapes;

import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;

public class GestureListener extends SimpleOnGestureListener {

private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;

@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        //From Right to Left
        return true;
    } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        //From Left to Right
        return true;
    }

    if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
        //From Bottom to Top
        return true;
    } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) {
        //From Top to Bottom
        return true;
    }
    return false;
}

@Override
public boolean onDown(MotionEvent e) {
    //always return true since all gestures always begin with onDown and<br>
    //if this returns false, the framework won't try to pick up onFling for example.
    return true;
}
}

I have the "ball" created in my MainActivity class, how would I call the onFling event of the ball? i.e, add the gesture listener to the ball (or each object randomly generated)?

share|improve this question
1  
Please describe the exact problem you're having, and only include the code related to the problem. –  Byte56 Oct 25 at 22:21
 
I can't get the "bitmap" or game object to fling when I swipe it. I know I need some "ontouch" code for the object but I don'tknow how to do that. –  Adam Short Oct 28 at 10:18
 
Can you update the question to include exactly how it's not working now and the snippet of code you're using to fling it? –  Byte56 Oct 28 at 17:56

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.