setLinearVelocity on new t2dStaticSprite
by Rob Tatnell · in Torque Game Builder · 12/12/2011 (2:55 pm) · 2 replies
Hi all,
Apologies for what is quite possibly a very n00b question, but hey, it's my first post :P
I'm creating sprites at runtime and adding them to my scene; I set their linear X velocity, however they are not moving. Do I need to enable their physics? If so how?
Here's my code:
Any help would be awesome! Thanks in advance
Apologies for what is quite possibly a very n00b question, but hey, it's my first post :P
I'm creating sprites at runtime and adding them to my scene; I set their linear X velocity, however they are not moving. Do I need to enable their physics? If so how?
Here's my code:
%splash = new t2dStaticSprite()
{
scenegraph = SceneWindow2D.getScenegraph();
class = splashClass;
};
%sceneGraph = SceneWindow2D.getScenegraph();
%sceneGraph.addToScene(%splash);
%splash.setPosition(%this.getPositionX(), %this.getPositionY());
%scale = getRandom(50,60);
%splash.setSize(%scale, %scale);
%splash.setImageMap(splashImageMap);
%splash.setLinearVelocityX(-100);Any help would be awesome! Thanks in advance
About the author
Industry guy gone Indie. Also known as Biscuit Quiff.
Recent Threads
#2
getLinearVelocityX() is returning the velocity I'm setting, but the sprite itself still doesn't move.
I have had to tick "Uses Physics" on other scene objects in order to get setLinearVelocity working, is there such a function for doing so within TorqueScript?
12/13/2011 (2:05 pm)
OK, I've tidied things up a bit.getLinearVelocityX() is returning the velocity I'm setting, but the sprite itself still doesn't move.
I have had to tick "Uses Physics" on other scene objects in order to get setLinearVelocity working, is there such a function for doing so within TorqueScript?
Torque Owner Rpahut
Set image map via 'imageMap' field
Either assign scenegraph to the 'scenegraph' field OR call for scenegraph.addToScene(), the latter is better I guess.
Size and position also can be assigned within {}.
Default physical settings should be okay for what you are trying to do.
Remove 'class = splashClass' and try again, most likely it is class code who prevents sprite from moving.
Also you can getLinearVelocityX() from the object and echo it to see what's the value there.