-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FlxAngle: Added angleFromFacing. FlxVelocity: DRY #1193
Conversation
*/ | ||
public static function accelerateTowardsObject(Source:FlxSprite, Dest:FlxSprite, Acceleration:Float, MaxXSpeed:Float, MaxYSpeed:Float):Void | ||
public static function accelerateTowardsObject(Source:FlxSprite, Dest:FlxSprite, Acceleration:Float, MaxSpeed:Float):Void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the logic behind removing the separation between x and y? Don't we lose flexbility that way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Gama11 Not exactly. If you have a separate X and Y you don't have any way of limiting the scalar speed. For example, if max x and y velocity are both 1, your max speed when moving horizontally is 1, but moving diagonally 2^0.5 ≈ 1.41.
Perhaps ideally we'd have both a maxSpeed and maxVelocityX/Y?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First, it is a matter of consistency. Currently acceleration
is given as scalar and maxSpeed
is given as vector.
Second, functionality-wise, like what @JoeCreates mentioned, I think most users expect the speed to be capped at a scalar maxSpeed regardless of the angle of movement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would set the X and Y speeds to .707 if you wanted a scalar speed of 1. Out of convenience, though, I'd rather tell it a scalar speed and have it sort out the vector X and Y components. When would you ever restrict the speeds differently?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MSGhero You might want X and Y speed limits on a grid based game, if you wish to have moving diagonally occur as quickly as moving horizontally or vertically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of letting the function calculate the acceleration vector based on an angle but not the same for maxSpeed?
If you have to set the maxSpeed x/y separately, I suppose you want to do the same for acceleration. (vise-versa)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that would be the case. It would be way overkill to have both. :P
(you cannot switch on expressions, even with inlined vars)
Btw, I suggest adding a |
*/ | ||
public static inline function angleFromFacing(Sprite:FlxSprite, AsDegrees:Bool = false):Float | ||
{ | ||
var degrees = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of interest, why did you change this to an if statement?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because Haxe's switch statement won't let you do this:
switch(sth)
{
case 1 + 1: 2; // error: Case expression must be a constant value or a pattern, not an arbitrary expression
}
Or I should define each inline vars before using the switch statement. e.g.
public static inline var UP_LEFT = UP | LEFT;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But, you can, it's Haxe: http://try.haxe.org/#416d9
It's called pattern guards: http://haxe.org/manual/lf-pattern-matching-guards.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah cool. Didn't know that. :)
FlxAngle: Added angleFromFacing. FlxVelocity: DRY
FlxWeapon: Big Cleanup + Update for HaxeFlixel/flixel#1193
Accelerate functions now take a single maxSpeed (instead of a maxSpeed separately in x/y)