Game Development Community

Swapping T2DSceneObject image file [SOLVED]

by David Horn · in Torque X 2D · 09/20/2009 (3:53 pm) · 7 replies

I've found a couple discussions on this, but haven't found any conclusions on this..


How can I change the image file that a T2DSceneObject uses?

Basically I have a rope on my wrestling ring, and I have several png files with different colors/kinds of ropes. So I just want to change the image file that it points to to something else.

I have the following:

T2DSceneObject testrope1 = (T2DSceneObject)TorqueObjectDatabase.Instance.FindObject("nt");

Right now, that T2DSceneObject displays "northRopeTop01.png"

how can I change it in realtime to "northRopeTop02.png"?

I want to do this for the mat, the apron, etc. so players can customize the arena.

Thank you

#1
09/21/2009 (1:18 pm)
Hi David,

I'm not sure what type of object your scene object is deriving from but my guess would be to just dynamically change the material instance to the material you would like to switch to. I can give you more detailed information if you tell me what the object type is.
#2
09/21/2009 (2:14 pm)
it's a T2DSceneObject.

I imported the image png into TXB. Then I dragged it on to the display area. So I believe it's a T2DSceneObject
#3
09/21/2009 (4:45 pm)
What he means is that T2DSceneObject's do not have a material, but T2DStaticSprite and T2DAnimatedSprite, which inherit T2DSceneObject, both do. So, he's not sure if you are using a static or animated sprite.
#4
09/21/2009 (5:05 pm)
Oh - my apologies.
It's a T2DStaticSprite.
#5
09/21/2009 (7:33 pm)
Thanks for clearing that up, Christopher.

Since it is a T2DStaticSprite you should be able to assign another RenderMaterial or anything dervied from RenderMaterial (i.e., SimpleMaterial for instance) to the Material property on the T2DStaticSprite. It looks like from the code it should immediatly take effect on the next frame render.

Let us know how it goes; I've never tried to change the material dynamically yet.
#6
09/22/2009 (10:42 am)
Works perfectly -

here's my code - should come in handy for multiple uses:

T2DStaticSprite myObject = (T2DSceneObject)TorqueObjectDatabase.Instance.FindObject("objectname") as T2DStaticSprite;
SimpleMaterial m = new SimpleMaterial();
m.TextureFilename = @"data/images/newimagetoswap";
myObject.Material = m;
#7
09/22/2009 (3:41 pm)
It'd probably save you some resources to search for the Material, if you have already used it and set it to the one thats already been used.