• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Android Flicking an object towards a direction

M

Mael

Guest
Hello everyone!

I'm quite new to the mobile programming and now stuck on a problem. My goal is to be able to flick an object, like a ball, that moves then towards the direction of the flick.

I tried to implement this with the event "Flick" and then point towards direction "diff X and diff y". And then set speed 5.

Sadly the game crashes every time with the argument that diff X has never been seen before.

Can maybe someone explain me how to do it correctly?

Thank you very much.
 
Check the documentation for "Gesture Flick." You need to extract the diffX and diffY from a ds_map called event_data:
Code:
flickVelX = event_data[?"diffX"];
flickVelY = event_data[?"diffY"];
You can rename those variables to whatever you want. Or even just replace them with hspeed and vspeed.

Here is the full flick example from the documentation:
The Flick event is only triggered when a touch/click has been held, dragged and then released and the distance between the last drag position and the release position is greater than 2 inches per second (this is the default setting, although this can be changed using the function gesture_flick_speed). This event will generate an event_data DS map which you can then use to get information about the event. For example:

Create Event
flickVelX = 0.0;
flickVelY = 0.0;

Flick Event
flickVelX = event_data[?"diffX"];
flickVelY = event_data[?"diffY"];

Step Event
x += flickVelX;
y += flickVelY;
flickVelX *= 0.7;
flickVelY *= 0.7;


The above code simply gets the difference in x and y position of the last Dragging event and the current Flick event, and if the movement has been greater than the flick threshold, it sets some variables that are used to the move the instance in the step event.
 
M

Mael

Guest
Check the documentation for "Gesture Flick." You need to extract the diffX and diffY from a ds_map called event_data:
Code:
flickVelX = event_data[?"diffX"];
flickVelY = event_data[?"diffY"];
You can rename those variables to whatever you want. Or even just replace them with hspeed and vspeed.

Here is the full flick example from the documentation:

thank you very much sir! :)
 
Top