#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# Advice please - Best approach for a drag and rotate actor?

Posts: 785Member
edited 7:33AM
Before I start my next GS project I wonder if anyone has advice on the best way to approach a drag and rotate actor.

I want to have several actors on stage that when touched can be moved/draged around the screen and be left when the touch is removed - No problem but I also want to be able to have this same actor(s) rotated 360 degrees when the user drags their finger around the actor.

Would the best approach be for 1 touch to move the actor around the screen and then if there are 2 touches for it to be rotated when the user moves (rotates their fingers)?

Or is there a way this could be done with just a single finger i.e. if the actor is touched in the middle it can be moved around the screen and if the actor is touched around the edges then it would be rotated?

This app will end up being for children to use to I need it to be simple and easy to interact with.

JCFord

• Posts: 247Member
Hey I thought I saw someone upload a template file. They were long blocks or paddles that could be dragged and rotated.
• Posts: 785Member
I have almost worked it out using some long maths and the good old magnitude but I will take a look thanks.
• Posts: 3,206Member
I would use your second method. Just have one circle actor.
In the center of the circle, I would have a "move" icon. (whatever that is!) I would try and make this icon circular so you don't have to worry which side is up.
Maybe some sort of crosshair?

You'll need two attributes: 'distanceFromCenter' and 'dragging'.

You can easily use magnitude to achieve this:

Rule
When all conditions are valid
Touch is Pressed
-----Change Attribute: self.distanceFromCenter To: magnitude(abs(TouchX-self.Position.X),abs(touchY-self.Position.Y))
-----Rule
-----When all conditions are valid
-----self.distanceFromCenter <= [the radius of the "move" icon]
----------Change Attribute: self.dragging To: true
-----otherwise
----------[rotate me]
otherwise
-----Change Attribute: self.dragging To: false

Rule
When all conditions are valid
self.dragging = true
-----Constrain Attribute: self.position.X To: Mouse.X
-----Constrain Attribute: self.position.Y To: Mouse.Y

That should do it.
I have also made a rotation demo which you are free to dig through. Replace the [rotate me] with your rotation logic.
• Posts: 3,206Member
• Posts: 785Member
Thanks firemaple I will have a look at your solution when I get back to my laptop. Once again many thanks.
JCFord
• Posts: 785Member
@ Firemaple - Although I had this working, your code was a lot smaller and cleaner than mine, so thanks works a treat. :-)
JCFord
• Posts: 1,400Member
http://gamesalad.com/game/play/56582 <-demo has pretty much the same has pretty much the same thing as FMG suggested (if I remember correctly...) if anyone is interested.
This discussion has been closed.