Search code examples
iosswiftchildrennodechildren

changing the position of all childs of a node except the parent


I have a main node and it has 5 childs. I want to change the position.y of the 5 childs without changing the position.y of the main node.

is there a way to do this? maybe something like:

for children in mainnode.children{
children.position.y = children.position.y - 10
}

I know that this isn't right, but maybe something like it.

I have been struggling with it for days now, anybody that can help me out?

EDIT: my question is: how do I edit the children of a node. (the example code I gave above is what I tried but didn't work: it gives error on the seconds line: "@value $T9 is not identical to CGFloat")


Solution

  • If all you need is to update the position of all the children try this:

    for child in mainnode.children as! [SKNode] {
        // Update the position
    }
    

    Your error was probably coming from the fact that children is of type [AnyObject] and so child was of type AnyObject, not SKNode.