KingCoder11
KingCoder11

Reputation: 416

Player stuttering while moving - Sprite Kit

My player is a SKSpriteNode. I am moving it with CGVectors and player.physicsBody!.applyImpulse(). This works fine, but as my player is moving, it seems to be stuttering to the left and right a lot. So to fix this, I tried changing some of the physicsBody properties. In the update function, I added this line of code: player.physicsBody?.friction = 0. This still changed nothing. So I thought that this stuttering was caused by the player touching the ground. So I added a new line of code in the update function: player.position.y += 1. Of course, due to the nature of this solution, the player now stuttered up and down, but was able to move left and right without a problem. This shows me that the problem is with some type of force when the player is touching the ground. How do I stop the player from stuttering?

Edit: I think it would be beneficial to also know that my "ground" is actually a bunch of SKSpriteNode put next to each other in a row to make it look like a tilemap.

Edit: My player's physics Body was setup using this line of code: player.physicsBody = SKPhysicsBody(rectangleOf: player.size)

Upvotes: 0

Views: 128

Answers (2)

KingCoder11
KingCoder11

Reputation: 416

I found a solution to the stuttering, and it was to simply change this line of code: player.physicsBody = SKPhysicsBody(rectangleOf: player.size) to a circle. By setting up the physicsBody as a circle, all stuttering is gone, but now I can't get the effect of my player standing on the ground.

Upvotes: 1

AD Progress
AD Progress

Reputation: 5146

You are probably using too many spritenodes try using SKTileMapNode. Will help you dramatically in terms of performance. There are tutorials on youtube and raywenderlich how to use them. Just watch and you’ll see it is quite simple to use

Upvotes: 0

Related Questions