0

Working on a designcode.io tutorial for making a SpriteKit game. Have an issue where adding player movement causes the player image/texture to disappear. Code snippet of the update() function below. Commenting out the last line player?.run(move) keeps the "player" to remain visible within the view. Adding that line in the code makes the player disappear.

Any idea what's happening? Is the player being pushed off screen, masked by another object, or "invalidated" by the function in some way? I'm stumped.

extension GameScene {
    override func update(_ currentTime: TimeInterval) {
        let deltaTime = currentTime - previousTimeInterval
        previousTimeInterval = currentTime
        
        // Player movement
        guard let joystickKnob = joystickKnob else { return }
        let xPosition = Double(joystickKnob.position.x)
        let displacement = CGVector(dx: deltaTime * xPosition * playerSpeed, dy: 0)
        let move = SKAction.move(by: displacement, duration: 0)
        player?.run(move)
    }
Corey
  • 1
  • 2

1 Answers1

0

Fixed it. In GameScene.sks, selected the joystickKnob node and found it's default X Position was -0.001. I presume that this was forcing the player off of the screen when viewDidLoad. By setting the X Position value to "0", the player is now visible again.

Corey
  • 1
  • 2