0 Favourites

How to create/move objects just inside the edge of viewport

  • On the start of layout - blue circles should be created at random locations within the viewport and move either at 90 or 180.

    The green circles should be created just outside the viewport on the Y axis (top/bottom) and randomly along the viewport on the X axis and move either at 90 or 180 (circles move in direction of arrows).

    I've tried many different ways - viewportleft/right, windowwith, separate, together, X/Y....

    But when i run the layout, some of the randomly created green circles are outside the edge of the viewport along the X axis, as shown in the image below.

    This is the problem i'm having difficulties trying to solve. The green circles should be created within the viewport no matter the width of the phones screen.

    If anyone knows a solution, it would be greatly appreciated. My gamedev has come to a halt trying to solve this major issue.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • Perhaps you can do this by using a choose expression for the Y value. So e.g.

    Set Green Circle X to random(960)

    Set Green Circle Y to choose(-20, 980)

    This means the X will be completely random within 0-960 like usual, but it will choose either -20 or 980 for the Y value so it'll always be just above the window or just below it.

    Edit: Oops, on rereading I guess I misunderstood the question.

    Does the viewport move? I don't see why you can't just adjust the X value of the positioning so that green circles can't spawn outside the edge.

  • Sup with that Thanks for the reply

    No, the layout is static. It's a bit taller than the actual window, this gives the disks time to be created out of view and move in their direction(s). I almost had the expression right, but they were still being created closer towards the ViewportRight than ViewportLeft. After about 6hrs of messing with it, I decided to go back to the original plan.

    They are now created off screen, just above and below the largest viewport, and 32 pixels away from the window on the X axis.

    Tested on 3 different phones and 1 tablet. Although the tablet does have the biggest viewport, the disks are about a ball and a half width away from the edges on the X axis, and on the phones they are only a few pixels away. This i don't mind too much. It looks even and uniform.

    Again, thanks for the reply.

  • That is the same question as ....

    And i gave you an example containing the answer. No reaction from you, and then now the same question here again. You just have to random the edge that i calculated for you in the other post. Does not even matter witch scaling you chose in the project settings.

    So lets try to give you the same answer (now broaden with randoms).

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