I'm trying to make a Snake game on Android in which the snake moves with swipe gestures.
I've tried a lot of ways to get this done but none of them seem to work for me. I haven't implemented a view - will that be a problem?
This is a sample I tried implementing based on a previous StackOverflow question - Android: How to handle right to left swipe gestures.
I created OnSwipeTouchListener.java as instructed. I ran into a bit of a problem with the usage, however.
In GameScreen.java (which is where all the touch events go), I added this as a sample -
onSwipeTouchListener = new OnSwipeTouchListener() {
public void onSwipeTop() {
Toast.makeText(MyActivity.this, "top", Toast.LENGTH_SHORT).show();
}
public void onSwipeRight() {
Toast.makeText(MyActivity.this, "right", Toast.LENGTH_SHORT).show();
}
public void onSwipeLeft() {
Toast.makeText(MyActivity.this, "left", Toast.LENGTH_SHORT).show();
}
public void onSwipeBottom() {
Toast.makeText(MyActivity.this, "bottom", Toast.LENGTH_SHORT).show();
}
};
imageView.setOnTouchListener(onSwipeTouchListener);
This causes a bunch of errors to show up (mainly involving imageView), and none of them could be resolved.
Would anybody happen to have an alternative implementation of swipe specific to my case?