[SOLVED] How do I detect an object in a random area?

Get help using Construct 2

Post » Mon Jun 15, 2015 3:35 am

Hi C2 community!

I'm trying to find a way to detect an object within an random internal area comprised between a central object and a line composed by dashes generated by the touch of the player around this central object.

I did this illustration below for you guys better understand the situation. If at least one of these objects stay in this random internal area, the player loses.

Image

I tried to make it through the Line of Sight behavior, calculating the area composed of each stroke object that makes up the broken touch and the central object, but didn't get success. :(

count_dash*distance(Central_Object.X, Central_Object.Y, Dash.X, Dash.Y)

count_dash is a varible that count every dash spawned by the touch of the player.

I thank you in advance your attention and collaboration. ^^

SOLVED BY @BlackHornet! Link of CAPX example below:

http://www.blackhornettechnologies.com/ ... tTest.capx
Last edited by lukezero on Tue Jun 16, 2015 2:01 pm, edited 1 time in total.
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Mon Jun 15, 2015 5:56 am

I would create a invisible object to be the area. It doesn't have any behavior or anything, it works just as a collision area. You could try that :D
B
17
S
7
Posts: 277
Reputation: 2,514

Post » Mon Jun 15, 2015 6:07 am

You could look at the Canvas plugin. You can draw your user defined area, flood-fill, then use rbgaAt to detect overlap.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Mon Jun 15, 2015 10:51 am

RayKi wrote:I would create a invisible object to be the area. It doesn't have any behavior or anything, it works just as a collision area. You could try that :D


@RayKi I need to create a random collision area within the dashed line. A static object isn't useful to accurately detect the internal area.
Last edited by lukezero on Mon Jun 15, 2015 11:02 am, edited 1 time in total.
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Mon Jun 15, 2015 10:54 am

blackhornet wrote:You could look at the Canvas plugin. You can draw your user defined area, flood-fill, then use rbgaAt to detect overlap.


Thanks for the suggestion, @blackhornet. :D
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Mon Jun 15, 2015 4:04 pm

Master @R0J0hound, I'm using the Canvas plugin (which is definitely the solution for this case), but I still cannot solve this problem.

I'm trying to draw a line with the canvas whenthe player touch the screen, so the beginning of the line should amend it in order to involve an object. This "circle" must be filled by the canvas, creating a temporary object to be detected for collisions.

I tried with Path, Move Pen, Draw Path and other with the Touch behavior, but I had no success.

Sorry to bother you, but I'm just asking for help because I am not familiar with this great plugin.

In advance thank you for your attention and collaboration. :)
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Mon Jun 15, 2015 4:19 pm

Sorry, I was just working on it. www.blackhornettechnologies.com/Constru ... tTest.capx

This uses two canvas objects, one to draw, one to do the hit-test. I've assigned imagepoints at the corner of the test sprite. When one overlaps a filled area, it is "hit".
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Mon Jun 15, 2015 4:33 pm

blackhornet wrote:Sorry, I was just working on it. http://www.blackhornettechnologies.com/ ... tTest.capx

This uses two canvas objects, one to draw, one to do the hit-test. I've assigned imagepoints at the corner of the test sprite. When one overlaps a filled area, it is "hit".


WOW! :shock:

Great job, @blackhornet dude!

I'm studing your CAPX now to implement it to my needs.

Thanks for your help! :D
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Tue Jun 16, 2015 2:50 pm

Hi @blackhornet! Sorry to bother you again, but your detection system now detects only partially the object. (the purple box sprite)

There is a way of detection occur only if the object is completely within the fill canvas color?

Thanks one more time for your attention and collaboration. ^^
B
38
S
9
G
3
Posts: 258
Reputation: 4,324

Post » Tue Jun 16, 2015 6:46 pm

You could just change the detection to see if 'all' ImagePoints are overlapping, rather than 'any'.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Next

Return to How do I....?

Who is online

Users browsing this forum: Fradno, Laurent and 11 guests