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

Discussion and feedback on Construct 2

Post » Fri Mar 14, 2014 6:46 am

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
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Fri Mar 14, 2014 7:34 am

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.
B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Fri Mar 14, 2014 7:50 am

(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
B
8
S
4
G
1
Posts: 205
Reputation: 1,354

Post » Fri Mar 14, 2014 7:52 am

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)
Image
B
74
S
28
G
12
Posts: 515
Reputation: 12,359

Post » Fri Mar 14, 2014 8:39 am

(looks my response wasn't posted again)

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

Dan
B
8
S
4
G
1
Posts: 205
Reputation: 1,354


Return to Construct 2 General

Who is online

Users browsing this forum: No registered users and 10 guests