Game Development Community

Object creation via customized editor import scripts

by Gianormous Games · in iTorque 2D · 03/22/2010 (9:52 pm) · 1 replies

Hello!

Just wondering if someone knows an existing thread etc that's pertinent, I wasn't able to find one. I'm hoping to find examples of creating static sprites etc from torque script running within the editor.

Background: I'm porting an existing game into Torque 2D iPhone. I can easily get the existing (27) levels into xml format - the scenegraph & object metadata.

The plan: I'm adding a script to the editor - invokable from within - that loads up and parses existing xml files. Works well. Now, I just need to be able drive object creation from the script - add new static sprites etc to the level from the xml.

Side note: Additionally, my level scenegraphs don't lend themselves well to either static sprites or tilemaps, so I'm planning to add a new type - something like a tilemap, but with irregular sprite placement - arbitrary rotations, scalings, positions, etc. Static sprites look far to heavyweight for the 2D 100% static terrain/props. Tilemaps aren't irregular enough. But, the runtime additions are outside the scope of my question, really.

The problem: I'm trying to isolate source in the editor that does something similar to what I want (either cc or cs would be fine). I'm looking for, say, code that adds a t2dStaticSprite to an existing level. However, being a torque noob I'm having trouble finding what I want. Mostly, what I see is static sprites being created and then added to an editor scenegraph for visualization purposes, I'm not seeing the static sprite added into a level file. Or... am I? If I add it to the level's scenegraph, is the scenegraph walked when the level is saved, and viola, I've added a static sprite to the level?

I'm a torque noob but an experienced game dev (mostly consoles, ue3, etc) - generally quite comfortable modifying an editor and runtime. I can continue digging through the source, but if anyone can point me to a good example it's appreciated.

GG

#1
03/22/2010 (10:48 pm)
Looks like I got it after all.. If anyone sees something shaky, let me know:

// Test script, just test creating a static sprite...
function createObject( %imageMap )
{
%lastWindow = ToolManager.getLastWindow();
if( !isObject( %lastWindow ) || !isObject( %lastWindow.getScenegraph() ) )
return false;

%scenegraph = %lastWindow.getScenegraph();

%staticSprite = new t2dStaticSprite() { scenegraph = %scenegraph; };
// %staticSprite.setImageMap( %imageMap.getName() );
// %staticSprite.setSize( %imageMap.getFrameSize(0) );
}

Thanks much.