Dynamically loaded images (using images not in the level editor)
by baylor wetzel · in Torque Game Builder · 05/25/2009 (7:18 pm) · 2 replies
Is there an easy way for a game to use images not imported into the level editor?
i'm making a paperdoll game where you dress up a doll. Users can create their own content - draw a new jacket, dump it in the Clothes/ directory (maybe with a text file explaining properties of it, like it's a coat) and in the game, there it is!
i can't use the normal TGB method of importing the image into the TGB editor because a)images will be created by users after the game has shipped and b)i hate, hate, hate the TGB editor's handling of images, at least once you get 200 of them. They aren't sorted, you can't organize them in folders, it doesn't detect and reject duplicates, you used to have to load them one by one (not sure if that's still true; i know it still is in the XNA version)
For a strategy game, i also want users to be able to create their own units, so that's another, less girly, reason for wanting to load images at runtime
i'm making a paperdoll game where you dress up a doll. Users can create their own content - draw a new jacket, dump it in the Clothes/ directory (maybe with a text file explaining properties of it, like it's a coat) and in the game, there it is!
i can't use the normal TGB method of importing the image into the TGB editor because a)images will be created by users after the game has shipped and b)i hate, hate, hate the TGB editor's handling of images, at least once you get 200 of them. They aren't sorted, you can't organize them in folders, it doesn't detect and reject duplicates, you used to have to load them one by one (not sure if that's still true; i know it still is in the XNA version)
For a strategy game, i also want users to be able to create their own units, so that's another, less girly, reason for wanting to load images at runtime
About the author
#2
To anyone else who wants to copy and paste this, i'm making the assumption that the file name and imagemap name should be the same and that the file name has no spaces
i didn't end up using the SetModPath. It seems to work, although who knows what hidden errors i've added by not doing this
For this part, i just needed imagemaps, not sprites, but a different part of the program programatically creates sprites. Most people will only need the first two lines below (new t2dStaticSprite() and scenegraph.addToScene). In my particular example, it's for a paperdoll where you can add different layers of clothing, with each clothing type having it's own image and layer so that hats show over hair and coats show on top of shirts)
05/29/2009 (4:40 pm)
You're right, it was actually pretty easy. Here's the function i ended up withfunction loadImage(%fileName)
{
%name = %fileName @ "ImageMap";
%fqn = $userContentDirectory @ %fileName;
%image = new t2dImageMapDatablock(%name)
{
imageName = %fqn;
imageMode = "FULL";
};
return %image;
}To anyone else who wants to copy and paste this, i'm making the assumption that the file name and imagemap name should be the same and that the file name has no spaces
i didn't end up using the SetModPath. It seems to work, although who knows what hidden errors i've added by not doing this
For this part, i just needed imagemaps, not sprites, but a different part of the program programatically creates sprites. Most people will only need the first two lines below (new t2dStaticSprite() and scenegraph.addToScene). In my particular example, it's for a paperdoll where you can add different layers of clothing, with each clothing type having it's own image and layer so that hats show over hair and coats show on top of shirts)
function createClothingLayer(%name, %layerNumber)
{
%layer = new t2dStaticSprite(%name);
dressUpLevel.addToScene(%layer);
%layer.setLayer(%layerNumber);
%layer.setSize(paperDoll.getSize());
%layer.mount(paperDoll);
}
Torque 3D Owner Aun Taraseina
1. Copy the users image to your game directory
2. Reset the Mod path (SetModPath(getModePath());) so your new image gets added to the resourceManager
3. Create a new imageMap dataBlock linking the image location to the new image you just added.
4. Create a new t2dStaticSprite using the new imageMap datablock you just created.