mobile/mouse "gestures"

Get help using Construct 2

Post » Sun Oct 16, 2011 4:50 pm

Is there a way to get a sprite to follow a mouse or touch gesture?

Ex.
if I draw a "c" shape on screen with the mouse or mobile touch, then the spirite should follow the path of Thr shape created

(this in theory I assume should move a sprite at an angle in a straight line)

Touch -> on touch --> set spriteStart.X to Touch.X
                                    set spriteStart.Y to Touch.Y
Touch -> on release --> set spriteEnd.X to Touch.X
                                         set spriteEnd.Y to Touch.Y
Sprite -> move --> sprite.X = spriteEnd.X-spriteStart.X
                               sprite.Y = spriteEnd.Y-spriteStart.Y
                               Move at angle (sprite.X, sprite.Y)

????
B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Mon Oct 17, 2011 6:58 am

There's a flow in your logic there.
Since you are drawing a "C", the "path" should be an array containing the x,y positionf of the mouse during the path was drawn, not just the starting point and the ending point.

So it seems to me you should put up some "record" system, that will keep in memory the points where the mouse went by and THEN move the sprite from positions to positions until it reaches the end point.

That would be for a case where you first draw your path and then move the sprite.

If the sprite is to follow the path as it is drawn, then every X sec, set the sprite position to the current mouse/touch position.
Depending on the interval X, the movement can be more or less precise.

To know about sprite movements, check this topic out.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Mon Oct 17, 2011 5:50 pm

@kyatric

With that being said, is there a way to create a "dynamic" array?

Or,
Create a static array
Move the mouse-> populate the array & count each set of coordinates
For loop to cycle thru the array to move the sprite
??? (seems like a lot of unnecessary coding...not sure)
B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Mon Oct 17, 2011 8:24 pm

This plug: Data Structures
Would be ideal using 2 timers and a lerp, plus another copy of the plug for the y, unless C2 gets variable vectors at some point.

You could use the array object as well, but you would be limited in how many nodes you could add.

Then again, it might be possible to create local variables here as well.
Dunno for sure have delved into them much yet.
Image Image
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

Post » Tue Oct 18, 2011 7:49 am

I've ported this from construct classic, original was made by R0j0hound i think :)


and the .capx:
http://dl.dropbox.com/u/45711709/gesture.capx
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Tue Oct 18, 2011 5:36 pm

Kewlbeanz thanx Ize
B
16
S
2
G
1
Posts: 43
Reputation: 1,473

Post » Tue Oct 18, 2011 6:37 pm

well its not really what you wanted originally but maybe you can do something with it :D
B
33
S
6
G
7
Posts: 338
Reputation: 7,424

Post » Sun Oct 30, 2016 3:04 pm

Sorry to reanimate this old thread, but the link from Ize does not work ...
Can anyone post an actual link/file/example?

Thanks alot and Happy Halloween :)
B
20
S
5
G
2
Posts: 175
Reputation: 3,462


Return to How do I....?

Who is online

Users browsing this forum: Megavolt, mnashwan, shinkan, stylie1 and 17 guests