Tuesday 29 January 2013

#3.6 Tutorial (LibGDX & MTX) Test_05_InputIntent 2


What if I just need to detect swipe intentions not minor drags on the screen. The very simple solution is again InputIntent class.

FOR EXAMPLE: When you get notification center in android, you need to drag abit longer, nut just minor drags like 4-5 pixels.






















SET DRAG INTERVAL

First I need to determine how much drag needed for a specific task, in my example below

        dragAmount = AppSettings.SCREEN_W / 5.0f;
        inputIntent.setTouchDragIntervalRange(dragAmount);


Drag amount is 1/5 of the Screen Width (So if you use Samsung Galaxy II, you need to drag 160 pixels, if you use the GSIII, you will need to drag 256 pixels)






















CHECK DRAG INTERVAL

It is again very simple, just use:

inputIntent.isTouchDragInterval() // This simple will return true if needed drag amount achieved which you set in above example (dragAmount) inputIntent.setTouchDragIntervalRange(dragAmount);

In my example I only want to detect drags to LEFT and RIGHT, I do not care for UP and DOWN drags, So if user drags to LEFT or RIGHT and if it is DRAG INTERVAL return true and do something.































EXAMPLE

The best example you can see in one my live wallpaper projects. "Christmas Live Wallpaper"

You need to drag a specific amount to UP and DOWN to switch between Christmas Tree and Christmas Objects.

NOTE: The InputIntent I used in this live wallpaper abit old version, back then it was only detecting by removing finger off the screen each time. The current InputIntent much more improved and better.

(Google Play)






















1 comment:

  1. I have a basic problem while writing the program to create a Live WallPaper in LibGDX.

    In Android, the very first thing is while extending my class to AndroidLiveWallpaperService, It doesn't override any of the method mentioned:

    public ApplicationListener createListener ()
    public AndroidApplicationConfiguration createConfig ()
    public void offsetChange ( .. )

    I had imported all the needed packages, but still I am not able to override those methods.

    ReplyDelete