0

I'm trying to get the player to move to the direction of the player touch without stopping, or direction of swipe would be better because it seems more natural. However I only can find out how to do so with SKAction.move(by: vector) but the location variable I get from touches.first is a CG point.

I'm not sure what a vector point is so I can't figure out how to convert the touch point to a vector point to make this happen.

Any help would be really appreciated. I'm almost finished with my player movement and excited to move onto whats next

  if let location = touches.first?.location(in: self) {
    let horizontalAction = SKAction.move(to: location, duration: 1.0)
        horizontalAction.timingMode = SKActionTimingMode.easeOut
      player?.run(horizontalAction)
6
  • You may want to go through this tutorial: raywenderlich.com/… .. at the end, the movement of the sprite changes each time the view is tapped. Commented Jun 9, 2020 at 19:57
  • @DonMag Thanks for the link. I actually visited that page first to find out how to animate. I've done some modifications to his code to suite my purposes but it does the same thing. Now i'm trying to move it in a direction without stopping. As the camera is centered on the player sprite i want it to forever go to the direction of the mouse and not stop at the point first touched. Idk if that makes sense? Commented Jun 9, 2020 at 21:33
  • "go to the direction of the mouse" -- is this an iOS app or a MacOS (desktop) app? Commented Jun 10, 2020 at 12:33
  • @DonMag I apologize, I'm using the Xcode simulator so I was thinking mouse. An app, I meant touch. Commented Jun 10, 2020 at 16:11
  • I grabbed that AnimatedBear project... changed the size of the bear so it wasn't so big... implemented touchesBegan() and touchesMoved() with the same code as touchesEnded() and the bear follows my touch around. Commented Jun 10, 2020 at 16:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.