Jump to content

Keyboard Instead of Mouse Control


fedora
 Share

Recommended Posts

Currently, I have this script in my application to move the player in a circle using the mouse (taken from this example: http://phaser.io/sandbox/CpErwgAd/play) :

    var mouseX = this.input.x;    var mouseY = this.input.y;        theta = Math.atan2(mouseX-cX, mouseY-cY)        var newX = Math.sin(theta) * radius;    var newY = Math.cos(theta) * radius;        rocket.x=cX + newX;    rocket.y=cY + newY;

I would like to change the above to key control ("A"/'D") -- but can't get the right code to work.  

 

FYI, I am using the cursor arrows for other movement with no problem.

 

Any assistance would be greatly appreciated.

Link to comment
Share on other sites

In case anyone is looking for the answer -- the below is thanks to the expertise of jmp909 (http://www.html5gamedevs.com/topic/18140-how-drag-sprite-around-circle/#entry107548)

 

here's one way to do it using Sin/Cos

http://phaser.io/sandbox/gXbgAMnK/play

 

and another using phaser's point rotation function (with a distance constraint... http://phaser.io/doc...nt.html#rotate)

http://phaser.io/sandbox/wDpGcNHm/play

 

I've taken 0 angle as the top of the circle, but that's not the normal way angles are measured so i've shifted the value accordingly

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...