Making objects
by Shiraz · in Torque X 2D · 03/13/2007 (8:20 pm) · 10 replies
Up till now I've been making objects using...
player = (T2DSceneObject)(TorqueObjectDatabase.Instance.FindObject("player") as T2DStaticSprite).Clone();
but instead of clones I want to make full objects; their own render material and stuff. Can anyone give me the syntax for that?
player = (T2DSceneObject)(TorqueObjectDatabase.Instance.FindObject("player") as T2DStaticSprite).Clone();
but instead of clones I want to make full objects; their own render material and stuff. Can anyone give me the syntax for that?
About the author
#2
(TorqueObjectDatabase.Instance.FindObject("player") as T2DStaticSprite).CopyTo(player)
as well but that doesn't copy over components (the ones defined by tgbx) as well. I'm beginning to think there's no easy way to do this.
03/13/2007 (11:08 pm)
No, I want all the attributes of the object "player" put into the Sprite player. So it's like a copy. I've tried (TorqueObjectDatabase.Instance.FindObject("player") as T2DStaticSprite).CopyTo(player)
as well but that doesn't copy over components (the ones defined by tgbx) as well. I'm beginning to think there's no easy way to do this.
#3
03/14/2007 (6:43 am)
Ah, I see. For that you use the clone function like you already are doing. To change the material all you would have to do is clone the object and just assign it a new material that you have made in code or in the editor (I'm not sure if there is a lookup for material names). As far as I know, a clone is a copy in every way shape and form.
#4
03/14/2007 (8:27 am)
Clone and Copy are the same. You have full access to do whatever you want to your new copy.
#5
03/14/2007 (1:31 pm)
I've found its sometimes hard to find a clone, if I don't give it a name before I register it. //new name _newClone.Name = "NewClone"; //then register TorqueObjectDatabase.Instance.Register (_newClone);
#6
template_obj.Name = "JonathonRules"
cloned_obj1.Name = "JonathonRules1"
cloned_obj2.Name = "JonathonRules2"
and so on..

03/14/2007 (1:50 pm)
Maybe this would be a good time to ask for default naming such as:template_obj.Name = "JonathonRules"
cloned_obj1.Name = "JonathonRules1"
cloned_obj2.Name = "JonathonRules2"
and so on..

#7
and all child objects should be "LostBoy1"
but what you are talking about sounds cool too...
03/14/2007 (2:59 pm)
I think all Parent objects should be "Pirate0"and all child objects should be "LostBoy1"
but what you are talking about sounds cool too...
#8
03/14/2007 (2:59 pm)
Do you think that would work?
#9
example:
It's good coding habit to use methods like these that reuse code as opposed to making each player manually. This makes your code dynamic so you can add things later on.
03/14/2007 (6:54 pm)
Well all the names of objects would have to be the same so you would have to do "LostBoy1," "LostBoy2," etc. but that's probably what you meant anyway. If you are going to be creating them many times I would suggest having one function that creates and names them etc. Keep a variable that stores their "depth" so to speak and then you can name them accordingly. example:
int _depthCounter = 0;
void CreatePlayer()
{
T2DStaticSprite lostBoy = (T2DSceneObject)(TorqueObjectDatabase.Instance.FindObject("Pirate0") as T2DStaticSprite).Clone();
lostBoy.Name = "LostBoy" + _depthCounter.ToString();
_depthCounter++;
}It's good coding habit to use methods like these that reuse code as opposed to making each player manually. This makes your code dynamic so you can add things later on.
#10
03/15/2007 (10:32 pm)
Hey Luke, that "+ ToString" method really does work!
Torque Owner Luke Larson