How to add a animated sprite dynamicly
by Le Roi · in Torque Game Builder · 06/14/2006 (1:39 pm) · 2 replies
EDIT : Code to add dynamicly
$Player1 = CreateActor();
sceneWindow2D.loadLevel($CurrentLevel.FileName);
sceneWindow2D.getSceneGraph().addToScene($Player1);
This works like a bomb ;)
Thanks
Le Roi
END EDIT
Hi
In the TGB I Specify that the Class for my AnimatedSprite is "X" ,
then i've got this code :
function CreatePlayer()
{
return new t2dAnimatedSprite( :X)
{
class = X;
};
}
$Player1 = CreatePlayer();
But when I call $Player1.setLinearVelocityX(10) - it has no effect ?!
Please help
Thanks
Le Roi
$Player1 = CreateActor();
sceneWindow2D.loadLevel($CurrentLevel.FileName);
sceneWindow2D.getSceneGraph().addToScene($Player1);
This works like a bomb ;)
Thanks
Le Roi
END EDIT
Hi
In the TGB I Specify that the Class for my AnimatedSprite is "X" ,
then i've got this code :
function CreatePlayer()
{
return new t2dAnimatedSprite( :X)
{
class = X;
};
}
$Player1 = CreatePlayer();
But when I call $Player1.setLinearVelocityX(10) - it has no effect ?!
Please help
Thanks
Le Roi
About the author
#2
$Player1 = CreateActor();
sceneWindow2D.loadLevel($CurrentLevel.FileName);
sceneWindow2D.getSceneGraph().addToScene($Player1);
This works like a bomb ;)
Thanks
Le Roi
END EDIT
Hi
Thanks although that ":X" is what someone on the forums referred to as "Naming" - it allows me to use c++ like instances :
new t2dAnimatedSprite(Actor)
{
Controller = 0;
};
function CreateActor()
{
return new t2dAnimatedSprite( :Actor)
{
class = Actor;
animationName = "PlayerIdle";
class = "Actor";
position = "-31.7 -4.31";
size = "3.34 4.46";
Layer = "20";
CollisionPolyList = "-0.592 -0.847 0.639 -0.847 0.639 0.893 -0.592 0.888";
mountID = "3";
};
}
Thus I can create more than one instance of the base class "Actor" - and thus have unique Actors without hardcoding them at compile time - or something like that.
Anyways I got it working , thanks for the help
06/14/2006 (2:12 pm)
EDIT : Code to add dynamicly$Player1 = CreateActor();
sceneWindow2D.loadLevel($CurrentLevel.FileName);
sceneWindow2D.getSceneGraph().addToScene($Player1);
This works like a bomb ;)
Thanks
Le Roi
END EDIT
Hi
Thanks although that ":X" is what someone on the forums referred to as "Naming" - it allows me to use c++ like instances :
new t2dAnimatedSprite(Actor)
{
Controller = 0;
};
function CreateActor()
{
return new t2dAnimatedSprite( :Actor)
{
class = Actor;
animationName = "PlayerIdle";
class = "Actor";
position = "-31.7 -4.31";
size = "3.34 4.46";
Layer = "20";
CollisionPolyList = "-0.592 -0.847 0.639 -0.847 0.639 0.893 -0.592 0.888";
mountID = "3";
};
}
Thus I can create more than one instance of the base class "Actor" - and thus have unique Actors without hardcoding them at compile time - or something like that.
Anyways I got it working , thanks for the help
Torque Owner Jason McIntosh
function CreatePlayer() { %sprite = new t2dAnimatedSprite() { class = "X"; scenegraph = someSceneGraph; }; return %sprite; }Good luck!