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

FlxMouse: add getters for justPressedTimeInTicks #2070

Merged
merged 2 commits into from
May 18, 2017
Merged

FlxMouse: add getters for justPressedTimeInTicks #2070

merged 2 commits into from
May 18, 2017

Conversation

adrianulima
Copy link
Contributor

@adrianulima adrianulima commented May 18, 2017

Added getters for times in ticks of mouse button inputs, also made comments more consistent.

This makes FlxMouseButton#justPressedTimeInTicks accessible on FlxMouse, it is useful on cases we want to know how long a button was pressed.

if (FlxG.mouse.justReleased)
{
	var timePressed = FlxG.game.ticks - FlxG.mouse.timeJustPressed;
	trace(timePressed < 500 ? "Mouse click" : "Mouse long press");
}

@Gama11
Copy link
Member

Gama11 commented May 18, 2017

This property is already exposed for FlxTouch - the naming should be consistent:

public var justPressedTimeInTicks(default, null):Float = -1;

Also, I just noticed we use Floats for ticks in FlxTouch / FlxSwipe / FlxMouseButton, but ticks is an Int... I can't think of a good reason for that, it probably results in a loss of precision.

@Gama11
Copy link
Member

Gama11 commented May 18, 2017

Opened a separate issue for the Float / Int thing: #2071

@adrianulima
Copy link
Contributor Author

@Gama11 I saw it is public for FlxTouch and it's equivalent for mouse is FlxMouseButton that is already public and consistent. I thought that FlxMouse was more like FlxTouchManager, that don't have this field, but allows user to access directly FlxTouch objects.

So since we can't have access to FlxMouseButton in FlxMouse, I added it there.
The reason to have a different name was on purpose. I thought in a different start of the property to avoid code completion showing them first when user type "presse..." or "justPresse..." and avoid confusion with the other bool properties.

But I can change it to justPressedTimeInTicks to keep consistency even at FlxMouse level, which names do you suggest for Right and Middle ones?

@Gama11
Copy link
Member

Gama11 commented May 18, 2017

justPressedTimeInTicksMiddle and justPressedTimeInTicksRight seems like the most consistent naming.

I'm actually not a huge fan of how this API works, I'd prefer if you did have to access the values through the mouse button instances:

FlxG.mouse.left.pressed;
FlxG.mouse.right.justPressed;
// etc

But I doubt we'll change that anytime soon, seems unnecessarily breaking.

@Gama11 Gama11 changed the title FlxMouse time in ticks of last press FlxMouse: add getters for justPressedTimeInTicks May 18, 2017
@Gama11 Gama11 merged commit 3a05835 into HaxeFlixel:dev May 18, 2017
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.

2 participants