Tweening a point in a circular motion

121 views
Skip to first unread message

puggsoy

unread,
Jul 14, 2014, 2:47:49 AM7/14/14
to haxef...@googlegroups.com
I need to tween FlxPoints in circles, but CircularMotion tweens objects. I can think of ways to work around this, but is there a more proper method of tweening points that I don't know about?

Gama11

unread,
Jul 14, 2014, 4:00:08 AM7/14/14
to haxef...@googlegroups.com
No, there's no simple way of doing this atm as CircularMotion takes a FlxObject as its argument. This would solvable if FlxObject had a position FlxPoint instead of a separate x and y coordinate...

You could probably achieve similar effects using FlxAngle.rotatePoint() or FlxAngle.getCartesianCoords() in conjunction with polar coordinates, but neither of them seem as convenient.

puggsoy

unread,
Jul 14, 2014, 5:06:10 AM7/14/14
to haxef...@googlegroups.com
Well, I managed to make a fairly simple workaround by rotating the point using FlxPoint.rotate() every frame using a pre-calculated increment angle (the total angle divided by the framerate times the duration). Do you think such a tween is worth considering though? It would be convenient if anybody else needed it (and I'd definitely use it in this project as well).

Will Blanton

unread,
Jul 15, 2014, 4:40:20 AM7/15/14
to
Hey - I made this method just for that a while ago: 

 /**
 * Places a child relative to a parent using degrees and angle from the center Point
 * @param CenterX Horizontal value of parent
 * @param CenterY Vertical value of parent
 * @param ANGLE Angle from parent
 * @param RADIUS Radius/Distance from parent
 * @return FlxPoint Position of child
 */

 
public static function placeOnCircle(CenterX:Float, CenterY:Float, ANGLE:Float, RADIUS:Int):FlxPoint
 
{
 
var a:Float = ANGLE * (Math.PI / 180);
 return FlxPoint.get(CenterX + RADIUS * Math.cos(a), CenterY + RADIUS * Math.sin(a));
 
}


So this might work for you if you have the center point already.

puggsoy

unread,
Jul 16, 2014, 10:58:54 PM7/16/14
to haxef...@googlegroups.com
I think FlxPoint.rotate() pretty much does that? Although, that's in the dev branch so it's not in the current stable release.


On Tuesday, 15 July 2014 20:40:20 UTC+12, Will Blanton wrote:
Hey - I made this method just for that a while ago: 

 /**
 * Places a child relative to a parent using degrees and angle from the center Point
 * @param CenterX Horizontal value of parent
 * @param CenterY Vertical value of parent
 * @param ANGLE Angle from parent
 * @param RADIUS Radius/Distance from parent
 * @return FlxPoint Position of child
 */

 
public static function placeOnCircle(CenterX:Float, CenterY:Float, ANGLE:Float, RADIUS:Int):FlxPoint
 
{
 
var a:Float = ANGLE * (Math.PI / 180);
 return FlxPoint.get(CenterX + RADIUS * Math.cos(a), CenterY + RADIUS * Math.sin(a));
 
}


So this might work for you if you have the center point already.

On Monday, July 14, 2014 2:47:49 AM UTC-4, puggsoy wrote:

Gama11

unread,
Jul 17, 2014, 7:00:20 AM7/17/14
to
FlxPoint#rotate() is the same as the current FlxAngle.rotatePoint() (except for some fixes) - it's just been moved.
Reply all
Reply to author
Forward
0 new messages