Motion of swipe in real time to another actor

epicstagepicstag PRO Posts: 132
edited October 2012 in Working with GS (Mac)
I have actorA at position 100,100 and actorSwipeControl at any position that covers the entire screen. I would like to be able to touch the screen at a position(say 500,200... but any position needs to work) and as I move my finger, have it alter actorA's position by the amount my finger moved, all in real time.

I can't figure out how to get the correct value out of this though. I should be able to take something like the difference between actorSwipeControl.firstTouch and the current touch position, but I can't figure out the proper formula to apply, and how to constrain the values. If anyone can help me, I'd really appreciate it.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879

    In an actor, make two (real) attributes: xOffset, yOffset

    Then make a rule:
    When mouse down
    -- Change Attribute: self.xOffset To: game.Mouse.Position.X - self.Position.X
    -- Change Attribute: self.yOffset To: game.Mouse.Position.Y - self.Position.Y
    -- Constrain Attribute: self.Position.X To: game.Mouse.Position.X - self.xOffset
    -- Constrain Attribute: self.Position.Y To: game.Mouse.Position.Y - self.yOffset

    That should get things started!
  • epicstagepicstag PRO Posts: 132
    You know I ended up using a different method to do what I needed, but I will definitely be using this behavior in the future for something, so thank you for the help. Gotta say, it's challenging going from an environment with complete OOP style of control(I'm a php/mysql coder on the side), to a new environment like this.

    But I'm pumping out ideas quick as lightning, so I'm loving this program.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    Glad you found a way to accomplish what you wanted. For the sake of future searchers, how did you solve this? Its always interesting to see the many way GameSalad can be used to solve a particular challenge.

    I do agree with you. GameSalad's great interface and methodology really frees us from the the constraints of conventional coding. It encourages ideas to just flow "quick as lightning" as you say.
  • epicstagepicstag PRO Posts: 132
    I ended up making a drag actor, and put a rule that stated:

    When mouse button is down{
    Change self.positionY to game.mousePositionY
    Constrain self.motion.linearVelocity.Y to 20*( game.Mouse.Position.Y - self.Position.Y )
    } else {
    Constrain self.motion.linearVelocity.Y to self.Motion.Linear Velocity.Y *0.95
    }
    Constrain game.dragVelocity to self.Motion.Linear Velocity.Y
    }

    Then I simply placed the actors that I wanted to drag, and:
    Constrain self.motion.linearVelocity.Y to game.dragVelocity

    The actors then move with the same speed that I am swiping. I actually added a few more constraints to the rule in the drag actor to limit the swiping to a certain area of the screen:

    game.mousePosition.X > 20
    game.mousePositionX < 200
    game.mousePositionY > 370
    game.mousePositionY < 730

    These are of course variable and irrellevant.

    A big thanks to tshirtbooth's tutorial vids on getting this method working. I cant wait to demo this app out to you guys. Any parents out there should get a kick out of my app.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,879
    edited October 2012
    Great Solution! Thanks for sharing it.

    Edit----
    Here is another variation that might be less processor intensive. It allows the rest of the physics engine to play nice with the actor. And it does not require an extra drag actor. (It does require you to define one attribute -- yOffset.) Just place the following into the regular actor:

    Change Attribute: self.Physics.Drag To:100
    When MouseDown
    -- Change Attribute: self.yOffset To: game.Mouse.Position.Y-self.Position.Y
    -- Constrain Attribute: self.motion.Linear Velocity.Y To: 20*(game.Mouse.Position.Y-(self.Position.Y +self.yOffset))
  • epicstagepicstag PRO Posts: 132
    I didn't try this out, but it looks really solid. I'll definitely use that logic in a future project for things. The solution with the drag actor ended up being perfect for my project, because I have a line of vertically scrolling buttons, so they are all able to be tied to the drag actor, and when I drag one, they all move.

    It works a charm and looks really nice. You're solution will work great with my side project though. Thanks for sharing that.
Sign In or Register to comment.