change variable based on coordinates

Get help using Construct 2

Post » Mon Sep 10, 2012 11:09 pm

Hello!

In my game I have this bar, and a sphere. Whenever the sphere is over the bar, the player must press spacebar. But, I want to have the player to check if this bar is red or green. If it's red, he cannot press spacebar.

My issue os That i need the bar to change colors when the sphere is about 100 pixels close to the bar. Problem is, the sphere can approach from left or right, and i can't calculate X that way.

Glad if you could help!=D
B
6
S
1
Posts: 56
Reputation: 862

Post » Mon Sep 10, 2012 11:26 pm

You missed the CAPX ^^

Do you want a simpler way? Make a check by overlapping with offset or, make a check with a invisible mask around and pinned to your bar.
ImageImageImageImageImageImage
Image
B
99
S
22
G
16
Posts: 1,338
Reputation: 21,237

Post » Mon Sep 10, 2012 11:48 pm

In terms of performance, how wold the mask imply at this game?
B
6
S
1
Posts: 56
Reputation: 862

Post » Tue Sep 11, 2012 12:02 am

what about checking distance between bar and sphere?

distance(bar.X, bar.Y, sphere.X, sphere.Y) < 100 -> change color
ImageImageImageImage
B
155
S
61
G
41
Posts: 2,577
Reputation: 34,324

Post » Tue Sep 11, 2012 12:23 am

[QUOTE=shinkan] what about checking distance between bar and sphere?

distance(bar.X, bar.Y, sphere.X, sphere.Y) < 100 -> change color
[/QUOTE]

@shinkan It will check the distance only of the origin point, right?

@Zerei the impact is near to zero, you can't feel the difference. I'm using it and it's rocking on my game.

You should use square objects instead of complex polygons, because more points on the polygon issue on performance. It's better to check 10 objects with 4 points on their polygons instead of 2 with 20 points.

This is my debugging interface, you can check all the collision masks, I implemented them on a single layout and did this layout check if it's on preview, if yes, it become visible, if not, invisible.

[tube]http://www.youtube.com/watch?v=pJFQftlOdH0[/tube]



ImageImageImageImageImageImage
Image
B
99
S
22
G
16
Posts: 1,338
Reputation: 21,237

Post » Tue Sep 11, 2012 12:47 am

distance(bar.X, bar.Y, sphere.X, sphere.Y) - yes, from the origin point

but you modified it as you want

distance(bar.X, bar.Y-(bar.Height/2), sphere.X, sphere.Y) - this will check between sphere origin point and bar top center.
ImageImageImageImage
B
155
S
61
G
41
Posts: 2,577
Reputation: 34,324

Post » Tue Sep 11, 2012 7:45 pm

Thanks Guys! It really helped!
B
6
S
1
Posts: 56
Reputation: 862


Return to How do I....?

Who is online

Users browsing this forum: bbjGames, celstrider, jpstudio, Lordshiva1948, mekonbekon, menos30, newt and 11 guests