Set animation frame based on mouse direction

  • Hello,

    I have seen various examples of this, however I cant seem to get this to work.

    What I am trying to do is:

    1. If mouse is moving Up set animation frame to 0

    2. if mouse is moving Down set animation frame to 1

    3. if mouse is moving Left set animation frame to 2

    4. if mouse is moving Right set animation frame to 3

    A capx would help so much for me to visually understand how to do this in Construct 2. I am able to do this kind of thing in Actionscript 3 but not CS2 :(

  • Every tick you would compare the previous location to the one before it.

    global variable "PreviousX"

    global variable "PreviousY"

    system every tick

    ->set variable PreviousX to Mouse AbsoluteX

    ->set variable PreviousY to Mouse AbosluteY

    compare system variable PreviousX < Mouse absolute X

    -> Sprite Set Frame "3"

    compare system variable PreviousX < Mouse absolute X

    -> Sprite Set Frame "2"

    compare system variable PreviousY < Mouse absolute Y

    -> Sprite Set Frame "0"

    compare system variable PreviousY > Mouse absolute Y

    -> Sprite Set Frame "1"

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • PERFECT :) thank you very much for the help!!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)