Changing Direction of Actor while dragging

twinpixtwinpix Member Posts: 49
edited November -1 in Working with GS (Mac)
I've got an actor that was created with the Make Draggable Actor Wiki.

Anyone know of how I can program a change of image so when I drag the actor to the right, he faces right and when I drag the actor to the left, he faces left?

I've been fiddling with setting custom attributes on the actor and checking it against the mouse X but I can't get it to work.

Help!

Comments

  • EastboundEastbound Member, BASIC Posts: 1,074
    Hey there,

    First, create a variable to monitor your actors position before being dragged. In the mouse click event, set this variable to the actor's position_x.

    Secondly, on your mouse release event, set this variable to your actor's position_x again.

    Then, simply create a rule that checks if position_x > *name of your made up x variable* change the image to facing right, and if position_x < *name of your made up x variable* change the image to facing left.
  • rebumprebump Member Posts: 1,058
    Need to store current self X/Y into "OldX" and "OldY". Do this in an "Every 0.01 seconds" timer or thereabouts. Constrain self X/Y to mouse (or touch) X/Y. Then constrain "self.Rotation" to "vectorToAngle(MouseX-OldX, MouseY-OldY)-90". Place all this in a rule when mouse button is down (or touch).

    This will work while the mouse (or touch) is moving around. When still pressing down on the mouse button (or touching) and standing still, your item will stay rotated at 90...so you may have to add some logic to get around that.

    Edit: Eastbound's may fit your situation more closely if you are only concerned with left/right. Mine was more for any angle.
  • twinpixtwinpix Member Posts: 49
    Thanks Eastbound! I tried something like that but I really need the actor to swap directions even if the mouse button is not released. So if the actor is dragged left then dragged right (all in one drag) the image swaps as the mouse direction changes. I'm not sure how to update the X variable and also check for the position of the mouse mid-drag. Ideas?
  • EastboundEastbound Member, BASIC Posts: 1,074
    twinpix said:
    Thanks Eastbound! I tried something like that but I really need the actor to swap directions even if the mouse button is not released. So if the actor is dragged left then dragged right (all in one drag) the image swaps as the mouse direction changes. I'm not sure how to update the X variable and also check for the position of the mouse mid-drag. Ideas?

    Just have it all in a timer every .01 seconds, similar to what rebump said.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Make two images for the actor, one for facing left and one for facing right.

    Create 2 attributes in the dragged actor, called something like 'dragging' and 'oldXPosition' (without quotes)

    dragging should be a boolean
    oldXPosition should be an integer

    Then create a Rule in the dragged actor, like this:

    Rule
    When all conditions are valid:
    Touch is pressed
    -----Change attribute: self.dragging To: true
    otherwise
    -----Change attribute: self.dragging To: false

    And then another nested Rule set, like this:

    Rule
    When all conditions are valid:
    self.dragging = true
    -----Timer: every 0.01 seconds
    ----------Change attribute: self.oldXPosition To: self.Position.X
    -----Rule
    -----When all conditions are valid:
    -----self.Position.X > self.oldXPosition
    ----------Change Image: To: [facing right image]
    -----otherwise
    ----------Change Image: To: [facing left image]

    That should do it.
  • twinpixtwinpix Member Posts: 49
    Thanks everyone for your help!
Sign In or Register to comment.