2017년 4월 15일 토요일

Dragging a sprite around a circular axis using touch.


Hello everyone. I'm new to ai2 and this forum too, I hope someone can point me in the right direction.

I need to create a very simple screen, where you drag a ball (sprite) around an invisible center.
So imagine a circular axis with a "ball" on it. And when you try to drag the ball, the ball will remain on the point on the axis closest to your finger.
Hope it makes sense.

--
Is > this < what you mean?

--
No sorry, this is just centering an object. I want to move it AROUND the center, by dragging it.

--
Like the hands on a clock?

--
I made a bad gif of what I mean. Imagine someone dragging them in this circle. Without user interaction, they would be still.

http://oi59.tinypic.com/2hfqs0h.jpg

--
If you keep adding 1 to the sprite's heading in a fast clock it will cause it to spin around its upper left corner.
Both your red and blue sprites share a corner, but one is 180 degrees away from the other in its heading.
Here's a simple spinning red line to try...



--
Abraham's solution works to attract a ball to a touched point.
If you need the balls to rotate about each other ...

The Canvas and ImageSprite PointInDirection blocks allow you to rotate an ImageSprite by changing it's Heading value so that it points to an x,y location that you touch.

I tried it with both the Canvas and ImageSprite versions and they both work for your example.
If you would have more than one set of balls on the canvas you would need to use the ImageSprite version for each set of balls (unless you wanted them all to point to where you touch).
The image I used for this was one layer from your example jpeg file.
--
Great. Apparently all of my previous answers are on mail.
But I've try again. I'm am almost there, thanks to the last post.
This is what I want, but with the user creating the motion by dragging his finger around and around the center of the screen.


So far I have tried using (StartX - StartY) + (CurrentX - CurrentY) to dimiter the speed of the rotation.
It looked really cool, but it wasn't exactly what I wanted.

Thank you all for your answers, I really appreciate it. And I want to do my own work, I usually do. Just can't wrap my head around this one.

--
That is exactly what > TwoTouch.aia < does. Click the link to download it then import it to try it out.
You drag your finger anywhere on or near the circles and they will spin happily.
It does this using the PointInDirection block.

--
Thanks a lot for all the help. This is perfect! I will post the finished app here when I'm done.

--
Please do NOT post the application APK here... read the posting guidelines.  If you want to post a link to it, that's fine.

--
I'm not, I'm posting the .AIA. Without the "source code" it's pretty useless to people here..

--
I don't see what is allowed to be posted in the Welcome message. 
Is is somewhere else?

--
Here are the posting guidelines: Posting Guidelines

--
Got it. Thanks.

--

댓글 없음:

댓글 쓰기