Xcode Scene Editor doesn't seem to offer a way to define layout constraints like with Storyboard so that you can use Scene Editor to visually place and organize static sprites (similar to how you can arrange UIButtons with Storyboard).
Could someone confirm these things are not possible with Scene Editor:
1) Position sprites relative to other sprites and the scene using constraints (i.e., center Sprite A relative to Sprite B)?
2) Assuming #1 is possible, then adjust layout constraints and sprite sizes based on device?
There aren't layout constraints in Sprite-kit similar to UIKit constraints where you for example flag auto-layout and all elements are re-positioned.
In this place it might not make sense in a context where you can have long backdrops with characters who constantly change their size, objects that disappear or reappear, other elements involved by the laws of physics.
As commented by Knigh0fDragon this is the reason for which SKSceneScaleMode
exists
The modes that determine how the scene’s area is mapped to the view that presents it
enum SKSceneScaleMode : Int {
case Fill
case AspectFill
case AspectFit
case ResizeFill
}
However in Sprite-kit there are SKConstraints
:
An SKConstraint object describes a mathematical constraint on a node’s position or orientation. Constraints are attached to nodes; after a scene processes any actions and physics interactions, it applies constraints attached to nodes in its node tree. Use constraints to ensure that certain relationships are true before a scene is rendered
So, in other words, SKConstraint
are used to limit the position and orientation of particular nodes, for example it can be used when you want your player stay or run to a particular position and you have some reference points/elements that the player must follow.
An example:
let range = SKRange(lowerLimit:50, upperLimit:150)
let leftConstraint = SKConstraint.distance(range, toNode:guardrail)
car.constraints = [leftConstraint]