Create 1 object on top of another chosen object.

Get help using Construct 2

Post » Mon Aug 27, 2012 3:24 am

EDIT: Realized I did not describe that properly. I want to select all the blocks of the same color that are also next to the block clicked on.

I have a grid of 99 sprites. [s]I am attempting to select all the blocks of the same color.[/s] When you click on a block it changes that blocks opacity to 50%. Then I spawn a sprite that is cross shaped, if any of the neighboring sprites are on the same animation frame, it changes their opacity to 50% (there are probably other ways of doing this but...). I only want it to create one cross, but it keeps creating crosses forever, they are all on top of each other, but they are there. How do I make it only do it once? I fear someone is going to tell me to read "How events work", but I must not be understanding something there.



gazoogle2012-08-27 06:05:24
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Mon Aug 27, 2012 11:48 am

Another detail - event 5 - I want it to be recursive (if that's the right word)

It finds all the adjacent sprites that are the same color, makes them opacity 50, and then checks all the new opacity 50 sprites for sprites on the same animation frame, and then checks those for matching neighbors, until there are no more.

It does that fine the way it is, but it just keeps creating the neighbor-checking sprite forever....
B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Mon Aug 27, 2012 3:55 pm

Right now, every tick that gamestateflag = 1 a sprite is created.

system: trigger once while true, might be what you want..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
53
S
16
G
8
Posts: 6,157
Reputation: 19,744

Post » Mon Aug 27, 2012 11:54 pm

So, I made a condition that changed the GameState Flag to 2 when the Number of sprites with opacity 50 was less than the number of "neighbor checkers". Destroyed the neighbor checker in the layout at the start of the layout, and when the click was negated.

B
34
S
4
G
8
Posts: 67
Reputation: 5,857

Post » Tue Aug 28, 2012 1:03 am

Instead of creating a cross on every sprite, you could just use one cross and move it around. Here's an example that does that. It uses a boolean "checked" to track which sprites have been checked already.
pickColors.capx (r100)

Here's another approach that does all the checking in one tick using a while loop and an array to store a queue of sprites to be checked.
pickColors2.capx (r100)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Tue Aug 28, 2012 8:54 am

Thanks for those examples. This is now solved in a couple of ways!
B
34
S
4
G
8
Posts: 67
Reputation: 5,857


Return to How do I....?

Who is online

Users browsing this forum: Kagubro, Yahoo [Bot] and 25 guests