0 Favourites

Drawing with Pen on Canvas -- how to get it to work

  • Hi,

    I am trying to use the Canvas plugin to draw with a stylus on screen (actually, I don't have a tablet (yet), and am using the mouse). Trouble is, I can't get it to work. Using draw point, you get a jitterly set of points, dependent on the processing speed of the event loop rather than a smooth line. Using draw line is complex since when does the user start or end touch of the canvas -- at least I haven't figured it out yet.

    Essentially I do: On Touch Canvas draw point Canvas.x, Canvas.y

    Any suggestions would be much appreciated.

    I need a way to smoothly and easily draw lines from one square to another. The squares are already drawn onto the Canvas.

    thank you,

    Dan

    p.s. BTW, I also tried the Plaster plugin, but using its quads to draw, I get the same jittery dots rather than a smooth line

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • That's because that is the actual input results. However long ago they figured away to get a smooth effect. Take a large sample of positions say 30fps of samples. Then average the results and draw on every 30fps. This will create a much smooth drawing effect.

  • (looks like follow up question, didn't get posted, due to an internet disconnect).

    How does one sample the location of input at 30 fps. I can see the each second event, which i could set at 1/30. But, how do i know where the current touch point is? Also any hints on how to average results would be great.

    Hmm, i would both sample at 30fps and draw at 30fps -- perhaps drawing should be less, say at 3pfs.

    many thanks,

    Dan

  • try this:

    onTouch canvas - begin path

    isTouching canvas - draw path with color, line width

    lineTo touch.x touch.y (if you got the canvas hotspot in the middle)

    lineTo touch.x-canvas.x touch.y-canvas.y (if the hotspot is in the top left corner)

  • (looks my response wasn't posted again)

    Many thank Lof. It works great (smoothly)and performs very well.

    Dan

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)
Similar Topics Posts Views Last Post
Unread sticky
4,517 857,435
Tinimations's avatar
Tinimations
Unread sticky
1,586 437,329
matriax's avatar
matriax
Unread hot topic
0 Favourites
[PLUGIN] Canvas
627 186,708
zenox98's avatar
zenox98