0

With UIDynamics it is simple to have the physics objects, called dynamic items, control custom views (or indeed anything you want) using the protocol UIDynamitItem with the three properties center, transform and bounds. I would like to do something similar with SpriteKit, but according to the manual:

Unlike views, you cannot create SKNode subclasses that perform custom drawing

Specifically, I would like to have the physics bodies control some vector graphics I currently have in a drawrect. There are two things I am after here:

  1. The first is to let the vector graphics move around like any other node.
  2. The second is to let position, angle and other properties change the exact position of some of the control points.

I am fairly certain that I could achieve this with UIDynamics and dynamic items, but then I wouldn't be able to use actions and other nice sprite kit features.

It would also seem that 1 could be handled by converting the paths to cgpaths and using shape nodes, but that would be limiting, and not cover 2.

Any suggestions?

Tom Leese
  • 19,309
  • 12
  • 45
  • 70
Gusutafu
  • 745
  • 6
  • 17
  • To synchronize a UIView with a Sprite Kit node, you need to establish the connection between view and node and update the view's position (transform), rotation and other properties from the node every frame. Override the didSimulatePhysics method to do so, forward it from the scene to your target node as needed (Kobold Kit makes that easy). Be wary that UIView uses a different coordinate system, so you will need to convert coordinates. This is just the principle, a full solution with code I don't have time for atm. – CodeSmile Dec 07 '13 at 22:03
  • Thank you, that sounds very promising! Your solution is to use plain SKNodes and do the forwarding in SKScene, where the nodes could be properties, or located using .name or similar, right? I imagined perhaps subclassing SKNodes and overriding setCenter (or similar) and forward that to my custom views. What would be the downside to this would you say, if it works at all? – Gusutafu Dec 07 '13 at 22:50

0 Answers0