Animation frame based on mouse position?

0 favourites
  • 5 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • I'm trying to change an animation frame based on the mouse's position relative to the object.

    I believe I've been through all the events and actions and searched Google multiple times. I just can't find a combination or answer that'll do what I'm looking for.

    Here's a couple of frames of my player object:

    <img src="" border="0" /> <img src="" border="0" /> <img src="" border="0" /> <img src="" border="0" />

    As you can see, "Set angle toward position" just doesn't cut it <img src="smileys/smiley2.gif" border="0" align="middle" />

    Say the mouse is at an angle of 90 relative to the object, it would show the first picture. And so on...

    How would I go about doing something like this?

  • Wakey

    One non mathematical way of doing it, is to create 4 triangle sprites. One representing North South East West (imagine creating a giant X over the middle of the screen)

    Then use

    On mouse over "North" set animation to "player north" etc

    then make the triangles invisible so you can't see them.

    Here's an awesome sketch

    This assumes your player is always in the center of the screen though.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If the player ISNT in the center of the screen, here's another way of doing it.

    create 4 events

    mouseAbsolute.X > player. X


    mouseAbsolute Y > player.Y

    -> set animation player to "north"

    MouseAbsoute.X < player.Y


    mouseAbsolute.Y < player.Y

    set animation player to "south"

    etc etc

    Make a event check all 4 locations based on the players postion, top left, top right, bottom left, bottom right.

    then change the animation based on that.

    only 1 will be true at any given time.

  • Or You could check if angle between sprite and mouse is between certain value.

  • Check out this thread. I think that'll cover what you need.

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