This is another "coming from Cocos2d/UIKit" type question, but is there any type of "tag" system for retrieving added children. For example, in both cocos2d/uikit I can assign an integer tag such as 3 or OPTIONS_MENU_TAG to a sprite, add that to a scene with an addChild type function then retreive that child at any point by doing something like Sprite sprite = scene.getChildWithTag(OPTIONS_MENU_TAG)
What would be the equivalent in PSM? I don't need to keep each instance I want to retrieve up in the class members do I? I notice there are something called "tags" in relation to actions...
Thanks in advance for any help!
Solved! Go to Solution.
Thank you for your question. Unfortunately there ins't a way to do it as straightforward as you mentioned. Instead of tags, GameEngine2D Nodes have a 'Name' property, which although there are no checks to see if it's unique, could be used in a similar way. If you enforce the application of unique names to these nodes, you could use them as follows:
//.... sprite.Name = "sprite_lhs"; scene.AddChild(sprite); //.... Node node = scene.Children.Find(child => child.Name == "sprite_lhs"); if(node != null) Console.WriteLine("Found : " + node.Name); else Console.WriteLine("Nothing found");
Alternatively, if you know the position that they were inserted in the Children's List, then you could pick out the Node using its index.
Please let us know if you have any more questions.
Thanks for your reply, I tried it for GameEngine scenes and it works like a charm
However it doesn't seem to work for UIToolkit scenes, as the Children list is implemented as a IEnumberable... I'm just hitting the documentation now to see how this works, but it seems a little odd that these two members are implemented slightly differently...