When subclassing SKNode, should the Frame property return a non-empty value?

411 views Asked by At

I'm subclassing SKNode to render a map that consists of many SKSpriteNodes by adding those nodes to my subclass.

All is working well but I noticed that the Frame of my node subclass is always 0.

I couldn't find anything about this in the docs, so: am I supposed to override the Frameproperty and return a correct value?

1

There are 1 answers

2
Ali Beadle On BEST ANSWER

The frame property is the frame of the node itself, ignoring any children. For an SKNode this is a position but zero width and height.

The frame is non-empty if the node’s class draws content. (https://developer.apple.com/reference/spritekit/sknode)

Which I read as: SKNode draws no content so it is correct for it to be empty.

The frame of the node and its children is provided by the method calculateAccumulatedFrame() and functions that need the frame of the sub-tree should call that and not reference the frame property.

So there should be no need to override frame for your SKNode. I never have, have similar constructs in a few apps and have not yet had problems...