Sprite Occlusion

Get help using Construct 2

Post » Fri Mar 22, 2013 12:05 pm

Hi

I think this may be my first post on here so - hello!

Ive been using C2 for a little while now and thanks to all of the amazing tutorial and forum posts by the community, have managed to figure out everything I have needed to without having to resort to the forums - so thank you! I have however, now reached a point where I am not really sure how to continue and as such would be really grateful if someone could give me a little nudge in the right direction as to what I might need to do.

The demo I have is quite simple. Every time you touch the screen it creates a circular sprite (which scales the longer you hold it down effectively a brush). I also have a different sprite (say a rectangle) on screen that will eventually be covered by the circular sprites if enough are drawn over it.

What I am try to achieve is this:

I would like to detect when the rectangle has been completely covered by circular sprites as illustrated in the image attached below.



I have tried visibility, overlaps and have looked at some of the LOS tutorials, but none seem quite right for my needs. Is there anything in Construct that might enable me to come up with a workaround?

Thanks in advance
B
7
S
1
Posts: 16
Reputation: 732

Post » Fri Mar 22, 2013 12:10 pm

That's a very interesting problem. I can't come up with anything terribly efficient at the moment...

Maybe @r0j0hound or @yann would be able to help with the Polygon or Canvas plugins.

If there's no efficient way to do it, I could think of some ways to do it, but the calculations wouldn't be able to run every tick - only on a 'check' trigger or the like.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Mar 22, 2013 12:25 pm

Thanks. If it helps with efficiency/CPU I should add that I will be limiting the number of circular sprites that can be displayed on screen at one time. Probably no more than 20. If needed, I could reduce this even more.Boomlet2013-03-22 12:26:22
B
7
S
1
Posts: 16
Reputation: 732

Post » Fri Mar 22, 2013 1:12 pm

One not too efficient idea: use an array with size of screen width/height where you track which pixels are shown and which not. Whenever new object is created, 'create' it inside the array as well based on radius/coordinates.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Mar 22, 2013 3:11 pm

Ok, that's interesting, thanks. Arrays I'm ok with but I'm a little unsure about the pixel tracking. Would you be able to elaborate a little more about how I might do this?

Thanks
B
7
S
1
Posts: 16
Reputation: 732

Post » Fri Mar 22, 2013 4:07 pm

Well I'm not a mathematician at all. So when I see your problem, I have a newbie solution (I am the noob of course). But perhaps it can help the thinking :

What about composing your "rectangle collision" with a multitude of little invisible pieces, like a puzzle. When one of these pieces is overlaped by a circle sprite, it add 1 to a variable (once). If the variable is = the number of pieces then we can consider the rectangle is hidden.
I don't know if I'm clear. :(

It's just a idea, perhaps not viable or efficient.KaMiZoTo2013-03-22 16:07:57
B
61
S
16
G
12
Posts: 314
Reputation: 11,307

Post » Fri Mar 22, 2013 4:24 pm

Thanks KaMiZoTo - that's a brilliant idea. I think I can integrate that idea into the design so that it achieves the same outcome that I'm looking for.

Cheers! Boomlet2013-03-22 17:12:38
B
7
S
1
Posts: 16
Reputation: 732

Post » Fri Mar 22, 2013 5:57 pm

You're welcome. :)
B
61
S
16
G
12
Posts: 314
Reputation: 11,307

Post » Fri Mar 22, 2013 7:02 pm

@boomlet yeah, that was the 'inefficient' idea I was considering - however if your rectangles are too big, you will allow blank spaces, and if they are too small the checking will be very slow!

Still should work, anyway. Try it out!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Sun Mar 24, 2013 9:22 pm

@sqiddster - Thanks also. Yes this is a definite risk. I have decided to change the design slightly so I don't need full object overlaps for this very reason. I'm going to use several 'sub-objects' instead which will achieve the same effect.

Cheers
B
7
S
1
Posts: 16
Reputation: 732

Next

Return to How do I....?

Who is online

Users browsing this forum: Aserak2012, Google [Bot], ManuelPerez and 23 guests