Question on movement of objects
by Adam Emrick · in General Discussion · 09/27/2011 (9:42 pm) · 3 replies
Where can I find more information on the movement of a sprite object? Specifically, functions similar to the example given in the rainx demo:
%this.setLinearVelocityX(-20);
%this.setFlipX(true);
I would implement the different rotations, such as going at an angle. (say northeast) Which segment of the documentation handles the movement functions?
Thanks a ton
%this.setLinearVelocityX(-20);
%this.setFlipX(true);
I would implement the different rotations, such as going at an angle. (say northeast) Which segment of the documentation handles the movement functions?
Thanks a ton
About the author
Recent Threads
#2
10/06/2011 (5:06 am)
Anything at all would be helpful. I'm not sure where to look up the movement functions.
#3
function YourObjectClass::onWorldLimit(%this, %mode, %limit)
{
%speed = 100;
// Set up a string comparison switch based on the %limit
switch$ (%limit)
{
case "bottom":
%this.setLinearVelocityX(0);
%this.rotateTo(130, (%speed * 2));
%this.setLinearVelocityPolar(125, %speed);
%this.dump(); //this is useful for debugging
case "top" :
%this.setLinearVelocityX(0);
%this.rotateTo(-50, (%speed * 2));
%this.setLinearVelocityPolar(250, %speed);
case "left":
%this.setLinearVelocityX(0);
%this.rotateTo(-125, (%speed * 2));
%this.setLinearVelocityPolar(125, %speed);
case "right":
%this.setLinearVelocityX(0);
%this.rotateTo(75, (%speed * 2));
%this.setLinearVelocityPolar(25, %speed);
}
}
11/10/2011 (11:39 pm)
For posterity, some sample code to move an object in circles:function YourObjectClass::onWorldLimit(%this, %mode, %limit)
{
%speed = 100;
// Set up a string comparison switch based on the %limit
switch$ (%limit)
{
case "bottom":
%this.setLinearVelocityX(0);
%this.rotateTo(130, (%speed * 2));
%this.setLinearVelocityPolar(125, %speed);
%this.dump(); //this is useful for debugging
case "top" :
%this.setLinearVelocityX(0);
%this.rotateTo(-50, (%speed * 2));
%this.setLinearVelocityPolar(250, %speed);
case "left":
%this.setLinearVelocityX(0);
%this.rotateTo(-125, (%speed * 2));
%this.setLinearVelocityPolar(125, %speed);
case "right":
%this.setLinearVelocityX(0);
%this.rotateTo(75, (%speed * 2));
%this.setLinearVelocityPolar(25, %speed);
}
}
Adam Emrick
KnightsOfZen Games