Game Development Community

Changing scene object materials on the fly

by Nerdy Inverse · in Torque X 2D · 07/29/2007 (8:27 pm) · 4 replies

What's the best way to change a T2DSceneObject material on the fly without using animated sprites ?

About the author

Recent Threads


#1
07/29/2007 (11:30 pm)
Its the same code. Just use a static sprite instead of an animated sprite. And make sure you are working with them both as Static Sprites. The drawback currently is that you have to have a static sprite already available for you to "get" the material from. the good news is, it doesnt have to be registered... ie:

Heres an example of something you might write into a movement component.


T2DStaticSprite newObject = (T2DStaticSprite)(TorqueObjectDatabase.Instance.FindObject("ObjectTemplate") as T2DStaticSprite).Clone();
then perhaps
T2DStaticSprite myObject = _sceneObject as T2DStaticSprite;
then

myObject.Material = newObject.Material;


WillO
MMI
#2
07/30/2007 (7:06 am)
Quote:The drawback currently is that you have to have a static sprite already available for you to "get" the material from.
Actually, that's not true. You can get a material from the TorqueObjectDatabase if you want, or even have a component property of the RenderMaterial type and assign the material you want in TXB.
#3
07/30/2007 (7:53 am)
Thanks for the quick reply, I'll try that.
#4
09/22/2009 (10:39 am)
EDIT
sorry - I replied to the wrong post - my apologies for the bump