PSM Libraries

GameEngine2D

GameEngine2D

Reply
09 Jul 2012
By: CeeBee2012 Member 76 Posts
Level 3
Offline
Accepted Solution

Node "Tags"

3 Replies 140 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!

Please use plain text.
Message 1 of 4 (140 Views)
Reply
0 Kudos
Level 6
 

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
Please use plain text.
Message 2 of 4 (136 Views)
Reply
0 Kudos
Level 3
 

Re: Node "Tags"

Hey,

 

This would seem to achieve pretty much the same. Thanks

Please use plain text.
Message 3 of 4 (125 Views)
Reply
0 Kudos
Level 3
 

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

 

Please use plain text.
Message 4 of 4 (102 Views)
Reply
0 Kudos