Allen

Phaser cannot draw a line when moving too fast

Recommended Posts

Hello guys,

 

I got an issue when I want to implement a drawing tool, if I move the pointer slow, it can draw a linear line, but if I move the point fast, it will have the gap between my 'brush' dot. I have attached a screenshot for this issue.Screen Shot 2016-07-03 at 9.10.05 PM.png

 

My planning solution is: when the pointer isDown or is dragging, start drawing. However, it seems there are not 'dragging' or 'moving' method for input.pointer. Is there any other ways that can solve this problem? Thank you very much.

Share this post


Link to post
Share on other sites

Hello,

I don't know the general way for this but can't you just store positions and fill them in (start/end positions and fill in between) or better use canvas lineTo or Phaser's line?

EDIT: Wonder if that helps with fast mouse movements though.

Share this post


Link to post
Share on other sites

Just to advance the idea above, when I got some time on my hands now :-).

You can probably save each point into an array when mouse moves and then draw that as lines with some approximations (some curve fitting would be probably fine here, there are some things like quadratic curve and so on in canvas, aren't there?). That way it will hopefully smooth out and removes the stuttering.

I'd love to see how you tackle this problem so could you post here some example (working not just code ;-)) when you get it working the way you want?

Share this post


Link to post
Share on other sites

You can detect when the pointer is down, when it is up and when it has moved - by taking all three of these things, you can simply draw lines between each point while the pointer is down. This is how virtually all paint apps work; some modern clever ones will try to make the lines between the points smoother but generally speaking, they're just drawing lines between the points the cursor is measured at each frame while the mouse button is down.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.