Greg McKenna
Greg McKenna

Reputation: 55

Player Sprite keeps slipping in Sprite kit

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first
    let positionInScene = touch!.location(in: self)
    let touchedNode = self.atPoint(positionInScene)

    if let name = touchedNode.name {
        if name == "jumpbutton" && isReady == true {
            isReady = false
            
            let boost = SKAction.applyImpulse(CGVector(dx: 0, dy: 300.0), duration: 0.1)
            
            
            touchedNode.run(buttonPressAction)
            player?.run(boost)
            
            let wait = SKAction.wait(forDuration: 1.2)
                           run(wait) { [self] in
                             isReady = true
                           }
                print("jumpbutton")
            }

I understand this is very vague but my player sprite just randomly starts gradually slipping either to the right or the left for no apparent reason. It is especially prevalent when I apply a vertical impulse as shown above. Any insight or help is appreciated. Also the body type is bounding rectangle as it seems to happen less than when it is alpha mask or bounding circle.

Upvotes: 1

Views: 49

Answers (1)

Greg McKenna
Greg McKenna

Reputation: 55

It turns out my images were not cropped correctly and therefore caused my player sprite to slip.

Upvotes: 1

Related Questions