2

After changing the anchor point on my SKTexture, my texture now has the desired anchor point, but my physicsBody does not. Before i changed the anchor point they were happy together at the same position.

visual

This is the only code i wrote changing the anchor points : rightDrop.anchorPoint = CGPoint(x: 1.0, y: 1.0)

How can I move the physicsBody so that it has the same anchor point as the texture?

Whirlwind
  • 14,286
  • 11
  • 68
  • 157
  • 1
    Texture doesn't have an anchorPoint. anchorPoint is a property found on a node and it defines how the texture is drawn relatively to the node's position. It is a visual propety and it has nothing with a physics body as you have already experienced. Now, you probably doing something wrong (wrong logic), but you may try to create a new physics body using an initializer which has a center parameter to achieve what you want. – Whirlwind Jul 06 '17 at 16:59
  • 1
    Still, I would say using anchorPoint here is wrong approach. What are you trying to achieve? – Whirlwind Jul 06 '17 at 17:04
  • You can specify the center point of your physics body, look at the inits:https://developer.apple.com/documentation/spritekit/skphysicsbody – Knight0fDragon Jul 06 '17 at 18:39
  • I have to be able to get this to work correctly, and have abandoned anchorpoints a while back @Knight0fDragon, and jennifer, and WW – Fluidity Jul 07 '17 at 03:56
  • What? @Fluidity. Just move the center point of your physics body to where your anchor point needs to be – Knight0fDragon Jul 07 '17 at 03:58
  • It can only be done on the init of a body – Knight0fDragon Jul 07 '17 at 03:59
  • @Knight0fDragon hmm I thought it was bugged .. last time I tried I couldn't get it to work – Fluidity Jul 07 '17 at 04:00
  • 1
    I have an answer on here solving this problem with all the math, I havent had time to look for it – Knight0fDragon Jul 07 '17 at 04:02
  • @Knight0fDragon that would be cool. because I've gone through about ten playgrounds a while back and 4-5 posts and couldn't get it to work – Fluidity Jul 07 '17 at 04:03
  • 1
    https://stackoverflow.com/a/34584013/270964 – Knight0fDragon Jul 07 '17 at 04:22
  • @Knight0fDragon I got it working using your code and some extra help from a colleague! I had to change the anchorPoints of the scene as well, after some tidying up the scene it looks all good! Thanks! :) – Jennifer Andrén Jul 10 '17 at 11:34
  • @JenniferAndrén, no problem, just an FYI there is a small slack group I am a part of that has a few developers that play around with sprite kit, if you want more info feel free to email me at knight0fdragon@gmail.com – Knight0fDragon Jul 10 '17 at 12:55

0 Answers0