0

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")

sdd
  • 889
  • 8
  • 29
  • without more context, this should work. I'm assuming you're talking about representations with views(because the coordinates).. – JDM May 06 '15 at 17:18
  • 1
    If you just update the children, the parent isn't affected. You need to clarify your issue. – rmaddy May 06 '15 at 17:27
  • but it's giving me an error on the second line of my example code: "@value $T9 is not identical to CGFloat" – sdd May 06 '15 at 17:36
  • Your question still isn't clear. As @rmaddy said, changing the position of the five children won't change the position of the parent node... – ABakerSmith May 06 '15 at 17:48
  • If you just want to get rid of error, try `children.position.y = children.position.y - CGFloat(10.0)` – saurabh May 06 '15 at 17:50
  • @ sasquatch: didn't fix the error, the 1st "position" and "y" are marked. @ABakerSmith: In the question I am saying I have 5 children, but in real I have like 50 children which keep getting more and more, all with the same name. So I need a function(I guess a for...in) to update all the position of the children at once. – sdd May 06 '15 at 17:57

1 Answers1

0

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.

ABakerSmith
  • 22,759
  • 9
  • 68
  • 78
  • error: braced block of statements is an unused close (1st line) use of unresolved identigier "child" (2nd line) But I guess solving the first line will solve the second line too, but what is the problem? – sdd May 06 '15 at 18:43