Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Sprite follow finger/pointer

Author
Message
Tokidokee
12
Years of Service
User Offline
Joined: 28th Oct 2012
Location:
Posted: 29th Oct 2012 01:14
Good day all!

Quick question from a (long coder but) new APK user. Apologies if that is literally simple, I could not seem to find the answer on the forum or help file.

I need to be able to move sprites by selecting and moving them. Think of moving blocks around with your finger.

I have tried various combinations of the "Hitting sprites" + "Moving sprites" codes, but to no avail. I need a smooth movement along the displacement following the finger (on a tablet), not just a point and click to a destination.

The solution must be staring at me...

Later on, the idea is to have gravity applied to some of these.

Any pointers appreciated.
Plystire
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location: Staring into the digital ether
Posted: 29th Oct 2012 06:44
This is the simple version, but should suit what you're after.

Capture the pointer location (and state) using the GetPointer functions. When the pointer is first pressed down, check for the sprite that "contains" the pointer location, then set a flag for dragging that sprite index.

I think from what you've described you're just not sure which commands return pointer information? If that's so, here's a basic list:
Quote: "•GetPointerPressed
•GetPointerReleased
•GetPointerState
•GetPointerX
•GetPointerY"


Hope that helps


~Plystire

A rose is only a rose until it is held and cherished -- then it becomes a treasure.
Hodgey
15
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Oct 2012 06:46 Edited at: 29th Oct 2012 06:46
Something like this?



Quote: "Later on, the idea is to have gravity applied to some of these."

Be careful when using setSpritePostion() on physics enabled sprites as it may disrupt the physics.

Edit-Plystire beat me to it.

lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 29th Oct 2012 17:22 Edited at: 29th Oct 2012 17:30
When you add physics you will enjoy the command CreateMouseJoint() and you can implement it something like this:




Please forgive me for not renaming the variables I used but they should be selfexplanatory. Let me know if they aren't and I'll send you my "input()" function to go along with this

EDIT: The number "600" in the CreateMouseJoint call is the force of the joint and is relative to the mass of the objects you're trying to move. If you want direct movement without any "swing" set it high.

My hovercraft is full of eels
Tokidokee
12
Years of Service
User Offline
Joined: 28th Oct 2012
Location:
Posted: 31st Oct 2012 01:17
Hi there,

Thank you for all the feedback. Having played around, I have found my mistake: a badly initialised "holding" flag. This is at least for the GetHit/Getpointer implementation.

I have found that I loose the tracking easily as I move the finger/mouse too quickly. I think I will move on to the mouseJoint one as I would think it is more robust.

Would that work with multi-touch?

Cheers
lilpissywilly
AGK Developer
14
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 31st Oct 2012 10:37
It would work with multitouch as long as you keep track of the joints since this only creates a joint with ID 1 and deletes ID 1 it would crash when you try to touch something while you already have something jointed.

My hovercraft is full of eels
Tokidokee
12
Years of Service
User Offline
Joined: 28th Oct 2012
Location:
Posted: 2nd Nov 2012 01:25
OK, basic tracking now sorted...and sprite sticking to the mouse with physics turning on/off as required.

All good now...

Login to post a reply

Server time is: 2024-11-24 02:01:40
Your offset time is: 2024-11-24 02:01:40