How to make an actor change direction based on the mouse position?
estc
Member Posts: 13
Hi all
I am writing a game that requires the actor to change it's direction based on where the mouse is. For example, at the start, my actor is facing right but as soon as my mouse move/pass to the back of the actor, it will animate and flip or change the facing of the actor to right.
Does anyone how i can that?
Many Thanks
I am writing a game that requires the actor to change it's direction based on where the mouse is. For example, at the start, my actor is facing right but as soon as my mouse move/pass to the back of the actor, it will animate and flip or change the facing of the actor to right.
Does anyone how i can that?
Many Thanks
Comments
If game.Mouse.Posistion.X > self.Posistion.X
Then change image (Right Picture)
Else change image (Left Picture)
Animate, instead of change image, would make the transition smoother... but that requires more images. If you're simply using rotate, and you don't want your character to look upside down, here's an alternative.
Make two copies of your actor, one left and one right. For the right-facing actor, do something like this...
If game.Mouse.Posistion.X < self.Posistion.X
Then spawn actor left, destroy
The left facing actor would be reverse.
I think I saw a bee game around here that could have benefited from such logic.
Destroy doesn't have to be used, as spawning and destroying may cause performance issues. Instead, "Change Position" could be used to move the left and right actors on and off the screen. When off the screen, they could be made inactive with an attribute and proper modification of the rules.
Thanks for the advice. My actor is working great now. Thanks a million.