How to ger distance between 2 objects on the differentlayers?

0 favourites
  • 3 posts
From the Asset Store
Welcome! I-Spy (Hidden objects) is an educational puzzle that is more than just seek-and-find activities.
  • How to get distance between two objects on the different layers if one layer is without parallax and 100% scale (UI layer) while other layer is with parallax and scaled

  • I suppose one way would be to use these system expressions.

    CanvasToLayerX(layer, x, y)

    CanvasToLayerY(layer, x, y)

    LayerToCanvasX(layer, x, y)

    LayerToCanvasY(layer, x, y)

    Cx = LayerToCanvasX(sprite.layer, sprite.x, sprite.y)
    Cy = ...
    Lx = CanvasToLayerX(sprite2.layer, cx, cy)
    Ly = ...
    D = distance(sprite2.x,sprite2.y, lx,ly)

    Another is to come up with the formula to do the parallax. It may end up being simpler but may take a bit of fiddling to get it right.

    Off the top of my head if there’s no rotation then

    X2 = ((x-scrollx)*parallax+scrollx)*scale

    Could be a possible start

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • this method is working, with a little addition, we got add the scale of the layer to the the "canvas to layer" value

    layer's scale is 0.9 so, I got to multiply the value by 1.11

    Thank you a lot

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)