mkjs
August 17, 2015, 5:56am
1
Hello!
Please, I am reading:
http://www.html5canvastutorials.com/advanced/html5-canvas-animation-stage/
This objects move all horisontally.
and I wonder how to get the object to move diagonally (angle 30, 45, 60 etc).
Does someone have a good beginners link or tutorial or example?
Many thanks inadvance.
To move object diagonally you should change both coordinates (X and Y).
object.x = object.x + speed;
object.y = object.y + speed;
This example will move object at an angle of 45 degrees
If you want another angle you have to use trigonometric functions:
var angle = 32; //angle in degrees
var angleRad = angle * (Math.PI/180); //angle in radians
object.x = object.x + speed * Math.cos(angleRad);
object.y = object.y + speed * Math.sin(angleRad);
mkjs
August 17, 2015, 8:59am
3
MANY THANKS !!! I will think it over!!!
system
Closed
November 16, 2015, 4:13pm
4
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.