Game Development Community

Sprite problems

by John Coyne · in Torque Game Builder · 02/23/2006 (3:47 am) · 2 replies

I cant seem to get my sprites to display at all. I'm creating a sprite inside a scriptobject, at first i thought that was the problem but I added a bit at the start to just display a sprite as a test, it doesnt even display that.

new ScriptObject(Infant)
{
   postion = "0 0";
   size = 10;
   speed = 5;
   name = "NULL";
   type = "infant";
   state = "idle";
   imageMap = "InfantImageMap";
   sprite = "NULL";
};

function infant::onAdd(%this)
{
   echo("Infant " @ %this.name @ " created");
   echo("State = " @ %this.state);
   
   //create a sprite to go along with this
   %this.sprite = new t2dStaticSprite() {scenegraph = t2dSceneGraph;};
   %this.sprite.setsize("20 20");
   %this.sprite.setPosition("0 0");
   %this.sprite.setImageMap(ForestMossImageMap);
   %this.sprite.dump();
   
   %this.controller(%this);
}

btw, the dump call in there works so it seems like it might be getting created then destroyed.

This is what i added at the start to test things out
%sprite = new t2dStaticSprite() {scenegraph = t2dSceneGraph;};
%sprite.setsize("20 20");
%sprite.setPosition("0 0");
%sprite.setImageMap(ForestMossImageMap);

I get the feeling i'm missing something really basic and obvious here :S

#1
09/15/2006 (1:15 pm)
So %sprite is not being drawn to the level when you have just the second code section? I think that's all you need to get the sprite drawn. You do need to import an image to the level called "ForestMossImageMap". I find that you want to have an instance in the level (and out of the viewpoint) so that TGB will see that it's needed. Otherwise TGB will sometimes remove unecessary images.

Richard N.
#2
09/15/2006 (4:00 pm)
You have scenegraph = t2dSceneGraph which will only work if your t2dSceneGraph is named "t2dSceneGraph" which I don't necessarily think is a good idea. Rename the scenegraph to be something else, "t2dScene" is common, and set the scenegraph to be that instead.