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="http://s7.postimage.org/e1naxmwo7/test01.png" border="0" /> <img src="http://s12.postimage.org/xi15t9lvt/test02.png" border="0" /> <img src="http://s17.postimage.org/girza7yuj/test03.png" border="0" /> <img src="http://s4.postimage.org/wz6q35ghl/test04.png" 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

    imgur.com/h1mb2mU

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

  • If the player ISNT in the center of the screen, here's another way of doing it.

    create 4 events

    mouseAbsolute.X > player. X

    AND

    mouseAbsolute Y > player.Y

    -> set animation player to "north"

    MouseAbsoute.X < player.Y

    AND

    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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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)