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
Posts: 56
Reputation: 712

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
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

Post » Mon Sep 10, 2012 11:48 pm

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

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
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

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
B
92
S
19
G
12
Posts: 1,192
Reputation: 18,276

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
140
S
58
G
36
Posts: 2,547
Reputation: 31,170

Post » Tue Sep 11, 2012 7:45 pm

Thanks Guys! It really helped!
B
6
Posts: 56
Reputation: 712


Return to How do I....?

Who is online

Users browsing this forum: Rezzon71, tarek2, Yahoo [Bot] and 19 guests