1

I’m using KVO to figure out if the resting property of my SKNode’s physicsBody has changed. But this runs tens of thousands of times per 30 seconds and is expensive.

Is there another way to figure out if the resting property changed inside a subclass of SKSpriteNode?

Adam Carter
  • 4,741
  • 5
  • 42
  • 103
  • What is the point of observing the resting property in your case? What actions should take place when property state is changed ? Some code could be useful though... Also, if don't want to be notified every time the resting property has been changed, then check it manually when needed. Probably you are overthinking this... – Whirlwind Mar 09 '16 at 11:52
  • I want to pause an `SKAction` when resting is true, and run the action on unrest. The trigger here is the physics body resting. Of course I would use the `update:` method, but `SKNode` or `SKSpriteNode` don’t have this and putting the code outside of the class wouldn’t follow OOP – Adam Carter Mar 09 '16 at 17:35
  • I understand that you are taking actions based on `resting` property state. But I was asking what exactly you are trying to do :) If you observe closely resting property, you will have something like true,true, true, false, true, true, true, false end so on, like many times in second. So, for example, resting property is not reliable if you want to say if node is moving or not...The node might look it is not moving, but the `resting` property will say different. Also, running an action (SKAction) inside update: method is not a good idea. Doesn't make sense(if I understand you well) ... – Whirlwind Mar 09 '16 at 17:39
  • Sure, I want to stop pause an `SKAction` when the node is has landed on the ground and is not moving in any given direction. – Adam Carter Mar 09 '16 at 17:44
  • `resting` property will not give you to accurate result. Your hero will land on the ground and stay there. At least it will look like it is not moving, but the resting property will change over time as I said. Like many times in a second. So you will have your action running even if it shouldn't. Read more here : http://stackoverflow.com/q/25471381/3402095 – Whirlwind Mar 09 '16 at 17:46
  • Is the `resting` property even KVO compliant ? Does that works for you? I mean, it might be, but I haven't tried by myself. – Whirlwind Mar 09 '16 at 17:47
  • Thanks, I’ll take a look. It worked well apart from the many times per second it would update, just observer for the key “physicsBody!.resting” – Adam Carter Mar 09 '16 at 17:51

0 Answers0