0

I create gems from an SKTexture (below), then assign it a physics body. When the user touches and moves the gem, I change it's actor point so that the gem isn't hidden under the users finger:

.anchorPoint = CGPoint(x: 0.5, y: 0)

However when I have showsPhysics set to true, I can see that the physics body is still at the gem's original anchor point (see attached image). Is this a bug? Is there some additional method I need to call?

    super.init(texture: skTexture, color: .clear, size: .zero)
    self.isHidden = true
    self.anchorPoint = CGPoint(x: 0.5, y: 0.5)
    self.size = CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height)
    self.zPosition = theZ.gem
    self.position = CGPoint(x: 0, y: 0 )
    self.name = fileName
    self.physicsBody = SKPhysicsBody(texture: SKTexture(imageNamed: fileName), size: CGSize(width: myGV.gemSize.width, height: myGV.gemSize.height))

screen shot of gem being under touchesMoved

LuisC329
  • 131
  • 8
  • Why are you trying to move the node with `anchorPoint`? Why not just move it with `SKAction.move(to:duration:)`? – West1 May 25 '21 at 08:54
  • 1
    No its not a bug, it is desired behaviour. You can read a little more [here](https://stackoverflow.com/questions/22095389/sprite-kit-change-anchorpoint-but-keep-physicsbody-centered) – JohnL May 25 '21 at 14:57
  • @West1 I'm not moving it with the anchorPoint. When a user drags it, I don't want it to be invisible because it's under their finger. – LuisC329 May 26 '21 at 01:16
  • @JohnL Ok, so not a bug. But an argument could be made that they could have worked it differently. Now I have to find out...does using SKPhysicsBody(texture: , size: ) assume a specific anchorPoint? – LuisC329 May 26 '21 at 01:22

0 Answers0