In the game I’m developing I need this function: being able to draw on the screen and to establish if the drawing is a determined shape (let’s say a rectangle, triangle or whatever).
So I wanted to use gestures, which are the easier way to do that; with the gesture builder I made a few shapes and I use them as models. The thing is, I can’t make it work with the AndEngine.
I need the GestureOverlayView, which is basically the drawing board, to be placed ON TOP of the scene of the game, so that I can see the scene itself with all the entities attached and I can also draw gesture.
Right now what I tried didn’t work, either the AndEngine stuff is shown on screen or the GestureOverlayView is, not both.
I’m new both with android developing and the AndEngine, so I’m kinda stuck here… do you have any ideas on how could I make it work? I looked everywhere but I can’t find anything useful…
I’ll leave the code of the gesture part below just for example, it won’t really work obviously if you don’t have any pre-made gestures in the path res/raw of the project:
public class ProvaGesture extends Activity implements GestureOverlayView.OnGesturePerformedListener
{
private GestureLibrary gestureLib;
public GestureOverlayView gestureOverlayView;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
gestureOverlayView = new GestureOverlayView(this);
gestureOverlayView.addOnGesturePerformedListener(this);
gestureLib = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gestureLib.load())
{
finish();
}
setContentView(gestureOverlayView);
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture)
{
ArrayList<Prediction> predictions = gestureLib.recognize(gesture);
for (Prediction prediction : predictions)
{
if (prediction.score > 1.0)
{
Toast.makeText(this, prediction.name, Toast.LENGTH_SHORT).show();
}
}
}
}
I didn’t see AndEngine part in your demo code. Your
ProvaGestureactivity should be extended from AndEgine’sSimpleBaseGameActivityorBaseGameActivitythen implementsIOnSceneTouchListener.Base on your idea, I guessed that you try to create a separated overlay view which handles only the gesture, so you must consider:
You have only one activity running at a time in android.
If you want to create an User-defined view overlaping the AndEgine’s surface view, you should see Andengine’s example:
XMLLayoutExample.The solution may be [suggested]:
Don’t forget to create your own layout:
overlaplayoutcontainingsurfaceViewandOverlayView