Convert coordinate from one layer to another?

0 favourites
  • 7 posts
From the Asset Store
Footsteps SFX One contains 400 sounds of steps and jumps on different surfaces.
  • Hi!

    I'm currently working on a survival shooting game roughly similar to gunbros or minigore, with enemy constanly generated and moving toward the player, inside a closed area larger than the window... (vertical and horizontal scrolling)

    What I'd like to do is an arrow for each enemy off-screen, like an indicator of the incoming danger... Something like that (you see the blue arrows?):

    <img src="" border="0" />

    My problem is that my enemies are on a layer with paralax while the arrows are on the GUI layer without parallax. They're not in the same "system of coordinates" and I don't know how to create a link between them.

    I'd like to know if there is a way to know the coordinates of an element from a layer but on another layer... a kind of conversion or something, giving the coordinate of an object in a specific layer). That would be awesome since I'd like to use this system not only for the enemies but also for bonuses and other things... A crucial element of the game, really.

    Thanks in advance for your help!


  • It could be the answer to my question (could it work with any type of objects?) but I don't know how to use the function in question <img src="smileys/smiley18.gif" border="0" align="middle">

    Layer functions



    Convert from canvas coordinates to layer coordinates. Useful for converting e.g. mouse co-ordinates to layer co-ordinates. See Mouse for an example.

    Thanks <img src="smileys/smiley9.gif" border="0" align="middle">

  • Maybe something like this?:

    Basically you move the arrow to the position of the object/monster in question, but clamp it to stay within a certain coordinates, in my case I use the window sizes.

    This should work since the coordinates are the same, regardless which layer you are on and if they are with or without paralax.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for your answer :)

    I tried your method, it's a clean way to display the arrow properly inside a fixed windows (I'll use it) but the initial problem seems to remain the same: it works only if the player stays inside the basic window but the scrolling makes a big mess of all of that :) :(

    (or maybe did I just missed something?)

    That's why I wanted to know if there was a method/function/something to convert the coordinates from a layer to another... It seems to be possible for the mouse but what about the objects?

    Je suppose it may be easier to find a solution, who knows?

    Thanks <img src="smileys/smiley12.gif" border="0" align="middle">


  • ViewportBottom(layer)




    Return the co-ordinates of the viewport in the layout of a given layer, by its name or number. Not all layers have the same viewport if they are parallaxed, scaled or rotated separately.

    You can convert the coordinates using those expressions.

    enemy x on layer 1 = enemy.X + ViewportLeft(1) - ViewportLeft(0)

    enemy y on layer 1 = enemy.Y + ViewportTop(1) - ViewportTop(0)

    There's an example in this post that converts coords on one layer to another layer with different parallax.

    But... why not have a separate normal layer for the arrows in between the game and GUI layers?

  • That's exactly what I was looking for :)

    Thanks both of you!!!

  • This is exactly what I was looking for, thank you!


    for layers that have parallax that is positive, be sure to subtract the difference between the layers, not add as above.

    Parallax is less than 100:

    enemy x on layer 1 = enemy.X + ViewportLeft(1) - ViewportLeft(0)

    enemy y on layer 1 = enemy.Y + ViewportTop(1) - ViewportTop(0)

    Parallax is greater than 100:

    enemy x on layer 1 = enemy.X - ViewportLeft(1) - ViewportLeft(0)

    enemy y on layer 1 = enemy.Y - ViewportTop(1) - ViewportTop(0)

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