Faced with the problem of spawn.

0 favourites
  • I have a layer "UI" he has disabled paralaks (equal to 0%)

    There is a layer "Objects" where all the objects are located. It has the usual parallax (equal to 100%)

    The UI is static, that is, when I scroll the screen, all the elements are in place. Next, I click on any place on the screen and create an object on it. And here the problem begins.

    I need the object to be created exactly in the place in which I clicked, and if I create it and specify the "Objects" layer, it will spawn somewhere else. If I specify to create an object on the "UI" layers, then it is spawned where necessary, but since the "UI" layer is not a parallax, it moves when scrolling behind this layer.

    I even spawned on the "UI" layer and then mixed the object onto the "Objects" layer, but at the same time its position immediately flew off and it mixed up.

    Initially, I call the spawn button on the "UI" layer, otherwise if it is "Objects", it will simply not be called.

  • what x/y are you using?

    if you are clicking (using the mouse) --> Create object at mouse.x mouse.y on layer "Objects"

  • Initially, I click on the display and a marker appears, then there are 2 buttons in this marker, each of which spawns the object. I click on the button 1 and in the same place an object should appear (I create the object at the sprite point of the marker)

    That is, I do not create an object immediately when I click. At first a marker appears with 2 buttons and depending on which button I click on it will create an object at this place.

    that is, the marker creates a new object at the sprite point 0 of this marker. Which appeared after pressing.

  • oh your UI button is on the 0x0 parallax? I think I understand.

    Maybe try using scrollx and scrolly?

    Create UIbutton on Layer "HUD" (0x0 parallax)

    Create SWAT on Layer "Human" at

    x: (scrollx - (viewportwidth / 2)) + UIbutton.x

    y: (scrolly - (viewportheight / 2)) + UIbutton.y

    There's probably an easier way, but I think this should work.

  • Yes, I create it on the UI, because otherwise it is not created if you start scrolling.

    That is, the UI layer is 1000x1000 px and the working area is 3000x3000px

    -----

    The system does not skip the expression viewportheight and viewportwidth

  • yeah I think you have to give viewport the layer. You are just trying to get the edge of the screen x/y then add the x/y of the UIbutton.

    if you make a Textbox and Everytick set text to UIbutton.x/y - also display scrolx/y you will figure out the calculation. or likewise run the debugger and just look at the x/y coords

  • (scrollx - (viewportwidth ("Human") / 2)) + Button_Point.x

    Here it helped, closer does not appear right in the place where I exactly need, but already better, the error in dozens of pixels

  • here is my test

    drive.google.com/open

  • Thanks a lot, it will help a lot.))

    I shot a video, I ask for my poor English. I tried to show what I want.

    Subscribe to Construct videos now

    And one more

    Subscribe to Construct videos now
  • To get from a point on one layer to the correct point on a different layer, you can use LayerToCanvasX / Y and then CanvasToLayerX / Y

    so, since you have the object Button_Point on the UI layer, and want to create a Swat object on the Human layer you would do this:

    System Create Object Swat on layer "Human" at CanvasToLayerX("Human",LayerToCanvasX("UI",Button_Point.X,0),0) , CanvasToLayerY("Human",0,LayerToCanvasY("UI",0,Button_Point.Y))

    that is a little confusing to see all at once, so I will break it down...

    You have Button_Point.X which is on the UI layer and want to know what X is under that on the Human layer, so you first convert to a canvas coordinate by:

    LayerToCanvasX("UI",Button_Point.X,0)

    lets call that cx, then you take cx and convert it to a point on the Human layer by:

    CanvasToLayerX("Human",cx,0)

    (and you have to do the same for the y coordinate)

    What happens if you scroll after you create the button_point - before you create the swat object? since the button_point is on the UI layer, it will not scroll with the map, and then it will be over a different place than where the player click...

  • You just saved me !!!!!!!!!!!!!!!!!! Thank you very much!!! Everything works as it should, I broke my brain.!) Thanks a million)

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • is that Button_Point on the 0x0 parallax layer? it needs to be otherwise it won't work.

    I updated the c3p to use a 3000x3000 layout and it works for me.

    drive.google.com/open

    I create a UIbutton on the HUD layer (para 0,0) and then I spawn something on the game layer (para 100,100). I then move the camera to a different area of the layout and it still works fine.

    However, I didn't know about CanvasToLayer (and vice versa), that seems like it will work as well.

  • UI is a layer - and its paralax is disabled (0%)

    On the Human layer (100% parallax). The UI layer is analogous to your HUD layer.

    As you can see from the video, what we see is a small rectangular screen, this is the resolution of the UI layer. Dalya, I shuffle the mouse and we see that the map is large.

    In your example, when we specify half of the viewing screen does not work, since the screen is larger.

    So as soon as the screen moves, the problem began. But AllanR offered a formula that fixed all this.

    Try to solve it. It works fine. The object spawns right at the point of the sprite.

    Your example works fine if the screen does not require scrolling, that is, does not go beyond the monitor zone.

  • jobel's way would also work - there are always lots of ways to do things.

    another option would be to save the Human layer X and Y coordinates from the original touch. You create the button_point at Touch.X("UI") and Touch.Y("UI"). You could have added instance variables and stored the Touch.X("Human") and Touch.Y("Human") to know where to create the new object later. Or you could have created the button_point on the Human layer, which would then scroll with the layer so the point doesn't end up somewhere unintended...

    but if it is working the way you want then great! :)

    the nice thing about layerTocanvas / canvasTolayer is that it will work from any layer to another, regardless of parallax or rotation.

  • Thank you again for your pom. And thanks to jobel, through your example, I also implemented a few moments!

    Many thanks friends!

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