Author Topic: how to rotate a FlxSprite in a circle with an angle determined by the position o  (Read 1636 times)

ashutosh sharma

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Hi Everyone...

I have been reading posts in the forum for last few months.. Thanks for all the help.

I have got myself into a big problem here, were i want to rotate a FlxSprite object in a circle(The object itself is a rectangle of 70*130), Now I want that object to rotate with an angle made by the center and the point where the mouse is placed within its radius. The code i Have used is like this..

Here I loaded the image:

loadRotatedGraphic("img/Ship.gif", 32, -1, true, true);

And here am i trying to rotate the image

if (FlxG.mouse.pressed)
      {
         var mouse_pos:FlxPoint = new FlxPoint(FlxG.mouse.x, FlxG.mouse.y);
         if (mouse_x>center.x && mouse_x < (center.x + width/2) && mouse_y < (center.y +height/2) &&mouse_y > center.y)
         {
            
            angularVelocity -= (FlxAngle.getAngle(getMidpoint(), arrow_end) -  FlxAngle.getAngle(getMidpoint(), mouse_pos));   
         }
         arrow_end = mouse_pos;
         
      }


Can anyone please help me with it because this code is not working, whenever i am placing the mouse in the area the object is rotating in a single direction and is not going to that point.

adamSrgnt

  • Member
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
There is a FlxU.rotatePoint() method.
Link to the API:
http://flixel.org/docs/org/flixel/FlxU.html#rotatePoint%28%29

It takes a pivot point, a point to be rotated, and angle, and returns the coordinates of the new location.

ashutosh sharma

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Thanks for helping..

But for that I need to know the exact point where the sprite is when the sprite is rotating.
The first time the Sprite rotates, its position changes so how will i get the current position of the sprite?

adamSrgnt

  • Member
  • **
  • Posts: 47
  • Karma: +0/-0
    • View Profile
Can you describe what you're trying to do a little more? Maybe a screenshot?  I couldn't get much from the code.