Advice please - Best approach for a drag and rotate actor?
JCFord
Member Posts: 785
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.
Thanks for your thoughts in advance
JCFord
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.
Thanks for your thoughts in advance
JCFord
Comments
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.
JCFord
JCFord