Changing Direction of Actor while dragging
twinpix
Member Posts: 49
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!
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
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.
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.
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.