How do I Draw a line

Get help using Construct 2

Post » Thu Jan 18, 2018 9:41 am

Hi all,

I would like to draw line across the screen with either touch or mouse.

I have searched for information to do this.
here;-
trying-to-draw-a-line-starting-from-the-point_t63632
Where an example is suggested but it doesn't seem to relate to drawing a line only creating a fixed line between two objects.
@Kyatric who suggested the above example has a page of lots of techniques, this was the only one about drawing a line.
On another thread I found a decent explanation
how-do-i-draw-lines_t91464?start=10
but it was shut down for being too old.

I have managed to implement the technique given in that second link, thanks @Masgame098, but while i can draw line, even a squiggly line, on release of touch or mouse, a line is continued from the last touch x, y to 0,0 and i can't understand why.
Does anyone have any ideas what could cause it?

https://drive.google.com/open?id=1jsfZb ... Aba3lO3sgU

I added this code to an already existing project, not a big project but with plenty of events. I have removed all the other stuff in this copy but i still get the line drawn on release.
B
8
S
1
Posts: 35
Reputation: 472

Post » Thu Jan 18, 2018 10:17 am

Try this:
https://www.dropbox.com/s/nfcn8bfqj898u ... .capx?dl=0

Note, that this method creates ~60 sprite instances every second, so don't make the sprite image too big and don't allow players to draw for too long without destroying old sprites.
Image

Did I help to fix a problem in your game? You can buy me a cup of coffee :) If you'd like to hire me, please see this post
B
19
S
9
G
158
Posts: 2,373
Reputation: 84,373

Post » Thu Jan 18, 2018 10:38 am

Hi, thanks that's great it works!

Previously, i thought the problem was down to timing, release caused the touch X / Y to return to 0 before the line was finished drawing, right? I just didn't know how to solve that.

The actual sprite has a fade effect with Destroy on fade out, the debug view shows the objects increasing and decreasing quite well.

Thanks again.
B
8
S
1
Posts: 35
Reputation: 472

Post » Thu Jan 18, 2018 10:47 am

I only have access to Construct 3 at the moment. But you can check this example to draw a line.

https://www.dropbox.com/s/10ys6rmhy764o ... t.c3p?dl=1

If you're using paster plugin you can paste the drawing on touch/mouse end, and delete all the sprites.

Edit: @dop2000 works as well, but my example uses distance to create a uniform distance between the sprites, so you can have dotted lines etc. Also only creates as many as needed, based on distance.
Follow my progress on Twitter
or in this thread Archer Devlog
B
49
S
22
G
19
Posts: 1,140
Reputation: 14,822

Post » Mon Jan 22, 2018 3:58 pm

@tunepunk thanks, I've downloaded the file you attached.
I don't have construct 3 yet, I'm waiting to finish my current project, but I will take a look.
B
8
S
1
Posts: 35
Reputation: 472

Post » Thu Feb 08, 2018 1:56 pm

Message: Okimi can only post plain text URLS until they have 500 rep. 2 URLS modified. Why?
Hello !

I recently developed a plugin do dynamicly draw lines (with dashed option). You can find it (with an exemple) on this links :

Plugin : https://tinyurl.com/yccb2ssq
Exemple : https://tinyurl.com/y8da2mxw

And the best : this plugin use only one sprite.

Have fun !
B
3
Posts: 1
Reputation: 177


Return to How do I....?

Who is online

Users browsing this forum: Cadwal, candyman201 and 5 guests