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?

JCFordJCFord Posts: 785Member
edited 7:33AM in Working with GS (Mac)
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


  • DookiDooki Posts: 247Member
    Hey I thought I saw someone upload a template file. They were long blocks or paddles that could be dragged and rotated.
  • JCFordJCFord Posts: 785Member
    I have almost worked it out using some long maths and the good old magnitude but I will take a look thanks.
  • firemaplegamesfiremaplegames 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:

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

    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.
  • firemaplegamesfiremaplegames Posts: 3,206Member
  • JCFordJCFord Posts: 785Member
    Thanks firemaple I will have a look at your solution when I get back to my laptop. Once again many thanks.
  • JCFordJCFord Posts: 785Member
    @ Firemaple - Although I had this working, your code was a lot smaller and cleaner than mine, so thanks works a treat. :-)
  • BarkBarkCoBarkBarkCo Posts: 1,400Member <-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.