Skip to content
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

Merged
merged 6 commits into from
Jun 27, 2014
Merged

FlxAngle: Added angleFromFacing. FlxVelocity: DRY #1193

merged 6 commits into from
Jun 27, 2014

Conversation

kevinresol
Copy link
Contributor

Accelerate functions now take a single maxSpeed (instead of a maxSpeed separately in x/y)

*/
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
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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?

Copy link
Member

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.

Copy link
Contributor Author

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)

Copy link
Member

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

@kevinresol
Copy link
Contributor Author

Btw, I suggest adding a resetSpeed parameter to specify whether velocity.set(0,0) or not

*/
public static inline function angleFromFacing(Sprite:FlxSprite, AsDegrees:Bool = false):Float
{
var degrees =
Copy link
Member

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?

Copy link
Contributor Author

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;

Copy link
Contributor

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

Copy link
Member

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. :)

Gama11 added a commit that referenced this pull request Jun 27, 2014
FlxAngle: Added angleFromFacing. FlxVelocity: DRY
@Gama11 Gama11 merged commit 0d8521d into HaxeFlixel:dev Jun 27, 2014
Gama11 added a commit to HaxeFlixel/flixel-demos that referenced this pull request Jun 27, 2014
Gama11 added a commit to HaxeFlixel/flixel-addons that referenced this pull request Jul 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants