Draw a line between 2 points

Get help using Construct 2

Post » Mon Feb 18, 2013 3:42 pm

Hi

I want to draw a line between two points, yet have been unable to figure out a way to do that.

My end game is to draw the path of the touch interface (or the mouse), in the same way it's done in Fruit Ninja.

So far, my approach has been to create a small round object under the Touch coordinates, and then have it slowly die. This creates a trace like it's shown in the screenshot:


http://s3.postimage.org/ej3f3dx0z/photo.png

But this approach won't get me the pointy line that's wide at the front, and gradually gets thinner as it fades away.
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Mon Feb 18, 2013 3:49 pm

Sorry if I misunderstood something, personally I would make an image of the slice.

And then:
- distance = abs(firstpoint.X - firstpoint.X) (so you get the size of the distance)
- image set width to distance
- image set position to firstpoint.x
- image set angle

you should also scale the height of the image a bit


This would just be one way, there are better ones with particles, i try to find one

B
15
S
6
G
6
Posts: 512
Reputation: 5,550

Post » Mon Feb 18, 2013 3:55 pm

In the how do I FAQ
=> A dash/slash effect like in "Fruit ninja" - LINK
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Mon Feb 18, 2013 4:14 pm

Wow, typed in a big explanation and my cookie expired. Sorry for this short one, but I need to get to work. I just lost 20 minutes of typing for some stupid security feature. Looks like 2 other people have made posts since I lost my work, sorry if I say something that has already been said, or if I am vague.

Here is the file I made for you :
https://dl.dropbox.com/u/1660874/scale.capx

in a nutshell, you spawn the sprite, have it set angle to Target.X and the Target.Y then you scale it until it hits the target. After it hits, then simply destroy it, or have it wait a split second and destroy.

Put the origin on the far left of the sprite to set the scale point. Have it scale while it is on screen. Have it destroy once it collides with target.
B
28
S
8
G
4
Posts: 767
Reputation: 5,940

Post » Mon Feb 18, 2013 5:42 pm

demo: https://dl.dropbox.com/u/23551572/C2-Ga ... index.html
capx: ninjaStroke.capx
polygon plugin: polygon.zip
polygon plugin topic: http://www.scirra.com/forum/topic62075.html

should work with multi-touch but I have no devices so I couldn't test
Last edited by Yann on Sun Sep 14, 2014 7:29 pm, edited 3 times in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Tue Feb 19, 2013 2:30 am

Thanks to all for the info. Deeply appreciated!
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Tue Feb 19, 2013 3:33 pm

Hi

I basically cut&pasted the Kyatric's linked project, and got this.



There's some kind of gap between each segment of the line. Actually is more like the Touch X&Y coordenates are not being red correctly (but when I run the linked project, things run fine) .
Anyone has any idea why this could be happening?
B
7
S
3
G
3
Posts: 53
Reputation: 2,459

Post » Tue Feb 19, 2013 3:39 pm

.capx?

What are your touch x/y values? You may want to try AbsoluteX/Y
B
49
S
14
G
3
Posts: 540
Reputation: 5,611

Post » Tue Feb 19, 2013 8:05 pm

Found the problem. It was the origin point not set to the left edge of the sprite.
B
7
S
3
G
3
Posts: 53
Reputation: 2,459


Return to How do I....?

Who is online

Users browsing this forum: flemmig, Matthew de, semaso, Skebab, Virpoja and 20 guests