Moving an actor in increments

Hi everyone,
I'm having a bit of trouble getting an actor to move how I want it too.
Basically I have 2 buttons both moving an actor along the X plane in either direction but I need to limit that movement with each button press. So for example you press button1 and the actor slides right by 40 then stops, press it again it moves right by 40 again, press button 2 and it will slide 40 in the opposite direction and so on.
In my current set up I have created a boolean attribute for the left and right movements called 'actor move L' and 'actor move R' which are false by default.
In the actor clip I have the rule:
`
if 'actor move R' = true
> Move Too X: self.Position.X +40, Y: 0, Speed 300, relative to actor.
`
The in the button I have the rule:
`
When actor receives event: touch is pressed
> Change Attribute 'actor move R' to true
Otherwise Change Attribute 'actor move R' to false
`
However this just means that for the duration of that button press the block keeps moving, and if "run to completion" is ticked it never stops. So basically, how do I get it to move by that distance of 40 and then stop until the button is pressed again?
I was able to make it snap abruptly by the distance by setting an integer attribute, constraining the actor's X position to that and the having the button increase the integer by 40, however I want to get a smooth movements between the two points.
Any help is greatly appreciated! Thanks,
- Olly
I'm having a bit of trouble getting an actor to move how I want it too.
Basically I have 2 buttons both moving an actor along the X plane in either direction but I need to limit that movement with each button press. So for example you press button1 and the actor slides right by 40 then stops, press it again it moves right by 40 again, press button 2 and it will slide 40 in the opposite direction and so on.
In my current set up I have created a boolean attribute for the left and right movements called 'actor move L' and 'actor move R' which are false by default.
In the actor clip I have the rule:
`
if 'actor move R' = true
> Move Too X: self.Position.X +40, Y: 0, Speed 300, relative to actor.
`
The in the button I have the rule:
`
When actor receives event: touch is pressed
> Change Attribute 'actor move R' to true
Otherwise Change Attribute 'actor move R' to false
`
However this just means that for the duration of that button press the block keeps moving, and if "run to completion" is ticked it never stops. So basically, how do I get it to move by that distance of 40 and then stop until the button is pressed again?
I was able to make it snap abruptly by the distance by setting an integer attribute, constraining the actor's X position to that and the having the button increase the integer by 40, however I want to get a smooth movements between the two points.
Any help is greatly appreciated! Thanks,
- Olly
Comments
On the button you could have your rules trigger when touch is released and have it reset the left or right booleans after say 0.1 seconds.
The distance is a little odd for some reason, it moves way further than 40 pixels, I guess I can adjust this manually though.
Thank you so much!
hope that makes sense.
The only question I'm left with now is the buttons are actually moving multiple actors (all instances of the same actor) in the same manner at the same time, do I need to set up an attribute for each actor, or is there a more efficient way of doing this?
Thanks again!
In the end I set up a new attribute for each actor and then edited each actor in the stage rather than in the library at the side. I don't know if this is the most efficient way to do this, but it has kept the library nice and clean and it all works
Using the method you guys gave me I've got the buttons working and moving the actor exactly how I wanted. The button only affects the X axis, so if I duplicate the symbol and reposition it in the Y axis it should mimic the movement along the X axis exactly when the button is released. However the new duplicate moves slightly faster. It still ends in the correct position, moves over the correct period of time, it just starts and finishes slightly ahead of the original. Not much, but enough to notice and break the game.
I thought it might be something to do with the easing so I tried setting that to linear but that has had no affect. I've tried duplicating it by holding Alt and by adding it from the main library but it still does it. Even though it's exactly the same in every way bar the Y position.
Is this something you guys have encountered before? Is it a general bug in Gamesalad?
Thanks again for all your help so far!
-Olly