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

Get help using Construct 2

Post » Sat Oct 22, 2016 6:42 pm

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).

Image

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.

Image

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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sun Oct 23, 2016 5:18 am

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.
B
50
S
23
G
17
Posts: 291
Reputation: 12,432

Post » Sun Oct 23, 2016 4:00 pm

@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.
B
38
S
18
G
19
Posts: 664
Reputation: 14,107

Post » Sun Oct 23, 2016 8:48 pm

That is the same question as ....
viewtopic.php?f=147&t=183203&p=1075509#p1075509

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).

https://www.dropbox.com/s/kgof97xedh1ce ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests