Jump to content

Rotation controlled by mouse


Recommended Posts

Hi, i'm new to PhaserJS and I was trying to make a group of sprites disposed in circle around the center of the canvas to rotate controlled by the mouse.


Initially I started doind by hand. I discover how to convert from polar coordinates to cartesians and set the position of each sprite in circle around the center.


Now I'm trying to make they rotate just using the mouse. I created a sprite to be the controller of the rotation. 

var cartesians = polarCordinateToCartesian(0, towerInitialRadious + 100);towersControl = game.add.sprite(cartesians.x, cartesians.y, "player");towersControl.inputEnabled = true;towersControl.scale = new Phaser.Point(2,2);towersControl.events.onInputDown.add(function(towersControl){    towersControl.selected = true;});towersControl.events.onInputUp.add(function(){    towersControl.selected = false;});

I used this code to set the selected element and this code to control the movement in the update function:

if(towersControl.selected){    var vector = {x: game.input.x - width/2, y: game.input.y - height/2};    vector = normalize(vector);    vector.x *= towerInitialRadious + 200;    vector.y *= towerInitialRadious + 200;    towersControl.x = width/2 + vector.x;    towersControl.y = height/2 + vector.y;}

So now I can drag the towersControl around the circle but when I stop clicking with the mouse it continues to move. Only when I stop clicking on top of the sprite that the movement stop. How can I make so when I stop clicking anywhere it's stop to move ? 

Link to comment
Share on other sites


  • Recently Browsing   0 members

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