Reply
09 Jul 2012
By CeeBee2012

CeeBee2012

  • Offline
73%
03 Rank
Progress
Playstation Staff
Accepted Solution

Node "Tags"

3 Replies 171 Views Created 09-07-2012

Hi there,

 

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!

Reply
0 Kudos
Message 1 of 4 (171 Views)
Reply
0 Kudos
jamesnorman91
05
/16

jamesnorman91

  • Offline
99%
05 Rank
Progress
Playstation Staff

Re: Node "Tags"

Hi CeeBee2012,

 

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.

 

Best regards,

James

 

PlayStation®Mobile Dev Team
Reply
0 Kudos
Message 2 of 4 (167 Views)
Reply
0 Kudos
CeeBee2012
03
/16

CeeBee2012

  • Offline
73%
03 Rank
Progress
Playstation Staff

Re: Node "Tags"

Hey,

 

This would seem to achieve pretty much the same. Thanks

Reply
0 Kudos
Message 3 of 4 (156 Views)
Reply
0 Kudos
CeeBee2012
03
/16

CeeBee2012

  • Offline
73%
03 Rank
Progress
Playstation Staff

Re: Node "Tags"

Thanks for your reply, I tried it for GameEngine scenes and it works like a charm :smileyhappy:

 

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...

 

Reply
0 Kudos
Message 4 of 4 (133 Views)
Reply
0 Kudos