# Line between two objects on different parallax layers

Get help using Construct 2

### » Thu Oct 22, 2015 4:08 pm

How would one go about creating and maintaining a line between two objects on different layers with different parallax scrolling values?

Currently I'm using code:

System: Every tick -> LineSprite : Set position to Object1 (image point 0)

System : Every tick ->
LineSprite set width to distance(Object1.X, Object1.Y, Object2.X, Object2.Y)
LineSprite set angle to angle(Object1.X, Object1.Y, Object2.X, Object2.Y) degrees

Object 1 and LineSprite are on layer1 (parallax 100,100) while Object2 resides on layer0 (parallax 50,50) When the viewport scrolls the Object1 end of the line stays where supposed to but the Object2 end doesn't. Any ideas how to get this to work and how to adjust the line angle/width to get it to attach to correct Object2 position (even when the layout is scrolling)? Thanks!
B
43
S
15
G
13
Posts: 161
Reputation: 9,785

### » Thu Oct 22, 2015 4:19 pm

Using these expressions:

LayerToCanvasX(layer, x, y)
LayerToCanvasY(layer, x, y)
Calculate the canvas co-ordinates above a position in layout co-ordinates for a given layer.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Thu Oct 22, 2015 11:36 pm

@LittleStain Thanks, I got closer and the angle is now correct but I can't get the end/width of the line to match with Object2 position. I must have something setup wrong here, can you elaborate a little more on how to implement it?
Here's a capx of my attempt: https://dl.dropboxusercontent.com/u/163 ... rline.capx
B
43
S
15
G
13
Posts: 161
Reputation: 9,785

### » Wed Aug 24, 2016 9:24 pm

hi @Waltuo , maybe it's too late! but anyway... just add "/ 2" to line width action.

"distance(Object1.Xpos, Object1.Ypos, Object2.Xpos, Object2.Ypos) / 2"

Hope it helps.
B
3
Posts: 1
Reputation: 177