Game Development Community

How to Add t2dAnimatedSprite by Script?

by Watermark · in iTorque 2D · 03/03/2012 (7:45 pm) · 2 replies

How can I create and add to stage (scenegraph?) a t2dAnimatedSprite in script code?

Mainly, I am thinking of using this to do Persistent Objects in my game that persists across levels. Currently I have to copy and paste my main character for example across all levels, and I find it really inefficient (nightmare to update). And I still couldn't get the persistent objs to work in the editor (iTorque 1.5), so thinking of using this method.

Also, when I switch levels, do I have to change the sprite's scenegraph or something like that?

If anybody can give me a really simple example that would be much appreciated!

About the author

Three iTorque 1.5 games published: Sorceria 1: The Mad Doctor RPG Sorceria 2: Sunken City Sagas: RPG Boardgame and Name Generator For more info see our site: http://wmrpg.weebly.com


#1
03/04/2012 (6:54 am)
If you are using t2dSceneWindow::loadLevel to load a new level, then the old scenegraph gets deleted along with any objects that are in that level.

How you deal with that depends on what you are trying to do. If you just want to avoid copy/pasting the same player object across all your levels then you could do something like

function t2dSceneGraph::onLevelLoaded(%this)
{
  %player = new t2dAnimatedSprite(Player)
  {
     (copy/paste out of a .t2d file as a template)
     sceneGraph = %this;
  }
}
#2
03/06/2012 (3:28 am)
It worked great! Thanks!