dynamic datablock creation
by Larry Jennings II · in General Discussion · 05/10/2011 (7:01 am) · 1 replies
i want to be able to change the image map for a static sprite based on a field given in a behavior.
Now i know the t2dstaticsprite has the setImageMap function, and how to use it. The problem is that i want the datablock supplied to be dynamic.
I plan on having a large amount of possible images. So its not very ideal for me to have to manually create data blocks for each image. Especially when i have plans of expanding.
I would rather like just iterate through a directory, and for each image found in it, create a data block.
But creating a datablock, for me at least, only works on the bottom-most scope ( not in brackets )
This is something i want to do. Assume %files is an array of filenames
so then later on in my behavior code i can
Can anybody point me in the right direction. I could write a small script for this in another language or such, but i was curious if there was a torque way.
Now i know the t2dstaticsprite has the setImageMap function, and how to use it. The problem is that i want the datablock supplied to be dynamic.
I plan on having a large amount of possible images. So its not very ideal for me to have to manually create data blocks for each image. Especially when i have plans of expanding.
I would rather like just iterate through a directory, and for each image found in it, create a data block.
But creating a datablock, for me at least, only works on the bottom-most scope ( not in brackets )
This is something i want to do. Assume %files is an array of filenames
%count = 0
for(%i=0;%i<%count;%i++) {
%file = getWord(%files,%i);
%datablockName = fileBase(%file);
// Create the dynamic datablock
datablock t2dImageMapDatablock(%datablockName){
imageName = %file; //required
imageMode = full;
};
}so then later on in my behavior code i can
if(!isObject(imageDisplayBehavior))
{
%template = new BehaviorTemplate(imageDisplayBehavior);
// ETC... Behavior stuff here
}
function imageDisplayBehavior::onLevelLoaded(%this,%sceneGraph)
{
// change the image map
%this.owner.setImageMap(%this.imageDatablock);
}Can anybody point me in the right direction. I could write a small script for this in another language or such, but i was curious if there was a torque way.
About the author
College student interested in serious game dev.
Torque 3D Owner Tim Scheiman
Ghost Ship Studios
but I make datablocks on the fly all over the place, and about the only difference between your code there and mine is that I have "new" where you have "datablock".
Also make sure your files list of names has the relevant path data it wants... like "~/data/images/tanks/tank1.png", etc.