How to determine mouse direction?

dre38wdre38w Member Posts: 79
edited November -1 in Working with GS (Mac)
I am needing to know how I would determine which way the player is dragging. Not dealing with position in scene space. But rather is the mouse dragging to the left or to the right?

Thank you.

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi dre38w, off the top of my head so untested: make an integer attribute called XPos, and make its value the starting x value of the draggable actor. Make an integer attribute called DragXPos. somewhere in your Rules, probably just after the drag Rules, use a Constrain Behavior, to constrain DragXPos to draggedActor.Position.X

    Then a Rule, when DragXPos > XPos
    ---do your stuff

    otherwise
    ----do your stuff

    Don't forget to add a Rule:

    When touch is released,
    Change attribute XPos to draggedActor.Position.X

    Hope that helps you and it works out.

    ----------------------------------------------
    http://davidgriffinapps.co.uk/

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • dre38wdre38w Member Posts: 79
    Thank you for the help! But I'm not sure if we're understanding each other. haha I already have an actor draggable. Before I confuse myself here's some of the logic.

    On area actor
    when touch is pressed turn a boolean on
    otherwise turn it off

    On draggable actor
    when boolean is true
    move with the mouse by use of the offset method

    Now what I'm wanting to do is determine which way the draggable actor is moving. This is slightly more difficult than I expected because there is no velocity on the draggable actor. So determining which direction it's moving, I would guess needs to deal something with position.

    But then that presents another problem cause what if the actor is on the right side of the scene but I want to tell it no you're moving to the left?

    I don't know if that cleared it up any?
  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    So you have a boolean that knows when you're dragging? Then say when boolean is true, check self.linearvelocity x. If self.linearvelocity x is >0, then you know its going right. If its < 0, then its going left.

    Here's a demo on swipe that may be illuminating as well.

    Edit: Just read your comment about velocity. Have you checked linear velocity already? It should detect it, even if the draggable actor itself doesn't have a velocity behavior.

  • dre38wdre38w Member Posts: 79
    Yeah I've checked to see if there was a Linear X velocity. It stayed at zero while I moved it back and forth. If I could use the velocity method that'd be perfect and that was actually my original plan until I found out there is no velocity. haha
  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    Just to clarify, you need to know the direction of the draggable actor before you release mouse, right?
  • LiquidGameworksLiquidGameworks Anchorage, AKMember, Sous Chef Posts: 956
    I think I thought of a wacky way of doing this.

    Make two real attributes
    Draggable Actor X
    Mouse Click X

    Constrain draggable actor X to draggable actor's self.position x
    When mouse is click, change game.mouse.click x to device mouseclick x (hopefully this registers the mouse click)
    Then, if game.actor x > game.mouse click - going right (so on and so forth)

    Untested. :)
  • dre38wdre38w Member Posts: 79
    Thank you very much! But that only works to an extent. Since I don't need to click on the actual draggable actor it won't change its direction until it passes the point of click. For example if I click on the right side of the screen and then I want to move left that's fine but now that I'm on the left hand side and start moving right again it won't change to see it moving to the right unless I pass that click point way on the right side of the screen.

    But these thoughts are definitely pushing me in the right direction.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    The only way I have gotten this to work is by using a timer (every 0 seconds)

    create 4 real self attributes

    self.X1
    self.Y1
    self.X2
    self.Y2

    every 0 seconds
    change attribute self.x2 to self.x1
    change attribute self.y2 to self.y1
    change attribute self.x1 to self.positionX
    change attribute self.y1 to self.positionY

    (outside of the timer)
    if X2 is > X1
    change self.goingright to true
    otherwise
    change to false

    if y2 is > y1
    change self.going up to true
    otherwise
    change to false
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    dre38w said:
    Thank you for the help! But I'm not sure if we're understanding each other. haha I already have an actor draggable. Before I confuse myself here's some of the logic.

    Well, I understood you, I'm thinking, not sure you understood me: you wanted to know how to determine whether the mouse was dragging an actor left or right, I gave a solution using the position of the dragged actor. This is because the dragged actor's position would match the mouse position, which you want. LiquidGames gave the same answer. SciTunes has another interesting solution but still using the dragged actor's position.

    ----------------------------------------------
    http://davidgriffinapps.co.uk/

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • Rob2Rob2 Member Posts: 2,402
    Search 'swipe' in the new project browser, there are quite a few demos that should help you, there is even one by me (very cool icon) :)
  • dre38wdre38w Member Posts: 79
    scitunes, that worked perfectly! I just needed to change the self.position.x to device.mouse.position.x.

    Thank you so much everyone!
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    dre38w said:
    scitunes, that worked perfectly! I just needed to change the self.position.x to device.mouse.position.x.

    Thank you so much everyone!

    I think in the code I was looking at I had been constraining the actors x and y to the mouse so that's why I used self.position instead of mouse position. Glad you got it working!
Sign In or Register to comment.