How do I make an object move on the edge of the screen

Get help using Construct 2

Post » Wed Apr 19, 2017 3:13 pm

Hi,

I have some difficulties to make an object move on the edge of the screen, it works but not perfectly.
I'm detecting the mouse position and, depends on it position, the object will be on the top, bottom, left or right edge of the screen.
When you move to the right and the object is on the right of the screen there is a small gap between the objet and the edge of the screen and i don't want it. : <
I try to use scrollx+windowwidth/2 for set the Y of the object to the right edge but when i'm not on fullscreen it doesn't work.

Any idea ?

An exemple of my code :
Image

My capx:
https://www.dropbox.com/s/fp23x6ko6kayip3/Camera.capx?dl=1
B
7
S
1
Posts: 30
Reputation: 787

Post » Wed Apr 19, 2017 7:42 pm

https://www.dropbox.com/s/3gtnd67ty83v9 ... .capx?dl=0

Some basic trigonometry, using the angle from center to mouse to set the position after determining which edge the object should be on.

The alternative no math solution would be to do the following every tick:
Set the object position to the center of the viewport
->Use a While loop to check if the object is still within the viewport - Move 1 pixel at angle (Angle from center of viewport to mouse)

This approach may be heavier in terms of performance though, although that may or may not matter relative to the rest of your project.
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303

Post » Thu Apr 20, 2017 10:41 am

Thank you dude !
B
7
S
1
Posts: 30
Reputation: 787


Return to How do I....?

Who is online

Users browsing this forum: Sparkz and 1 guest