coloring sprites in a function - picking problem

Get help using Construct 2

Post » Fri Mar 22, 2013 12:37 pm

Hello, I am searching forums & FAQ & tutorials desperately for many days to solve my little beginner problem. It is my very first question in this forum & I hope I am not expressing myself too complicated:

Im creating sprites (circles) in an array (FOR EACH XY), assigning colors to them, then creating another sprite (the green corners) and calling a function to check, if the circle next to it is either blue or purple and making it the same color. The last part does not work obviously, the corners stay green and dont turn blue or purple. The only corner picked & changing color is the on at the very bottom with the very first UID

I added a textbox to prove if the 2 function parameters are passed correctly, which seems to be working. Apparently I havent understood when parameters get lost in new subevents or not passed to functions that are outside the loop or something else...

Im planning to add more conditions to check the surrounding circles for color and place the corners animation frame accordingly after I figured out the basic problem here. Can you help me please?

corners staying green:


B
10
S
4
G
4
Posts: 23
Reputation: 3,152

Post » Fri Mar 22, 2013 12:51 pm

uhm I forgot the https://www.dropbox.com/s/u8c8dg7yincu53x/simpletest.capx
B
10
S
4
G
4
Posts: 23
Reputation: 3,152

Post » Fri Mar 22, 2013 12:58 pm

You have a visibility problem, which in my opinion is the most illogical and annoying feature of Construct 2: objects created cannot be referenced(picked) before next top level event.

In your case I'd reformat your code to use CornerSprite 'On created' rather than the function.
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Mar 22, 2013 1:25 pm

first of all thank you very much vee41 for your answer!

yes, formerly I was doing the setanimationframe as you suggest right just after creating the corners directly in the FOReachXY but soon I realized that I need a function because the function as it is simplified here will be expanded to check for many many conditions from neighboring colors that I left out of this example. And I dont want to redo it like 15+ times.

I read that a wait = 0 is used to have a fake event that triggers a next top level event? A function itself doesnt seem to be a such an event, because its only triggered when called, right?

Another thing makes me scratch my head, the distribution order UID indices for the corners seems to be vertically alligned in this example while the colors to the circles are being distributed horizontally following the array indices. These different index orders will be quite a complication when I will need to compare their values among each other. colorvalue of corner with UID and colorvalue of circle = array at x/y. damn!

Im very thankfull for any structuring hints :)
B
10
S
4
G
4
Posts: 23
Reputation: 3,152

Post » Fri Mar 22, 2013 2:04 pm

Yes, wait 0 can be used to 'break up' events. Here is what I came up with, made few other changes to the project. Colors can be now set with single event, no matter how many you add. That should simplify things quite a bit.

I wasn't really sure what your final intention on picking and choosing colors for corners is, so I just set the to pick the color of closest circle.

Also notice how I used local variables 'blue' and 'purple' to keep things a bit cleaner. I never like to reference to a number inside code, rather into meaning of that number :)

Colored corners
B
24
S
8
G
7
Posts: 756
Reputation: 7,192

Post » Fri Mar 22, 2013 3:03 pm

oh wow great stuff, there is lots of new things to lean from your version here, it so freaking CLEAN! great is also the idea with the identical & consistent animationframe numbers for circles & corners.

what I want to achieve as final result is a map generator with
smooth transitions for circles next to each other making them look connected.

I had an older capx version of this where it "almost" worked but I need a more generic solution like yours:


So my next endevour is to check what colors are the circles not only nearest but also above, below, next to each other etc. and then dependent on those conditions to assign colors to the particular corner. Ill try :)
B
10
S
4
G
4
Posts: 23
Reputation: 3,152


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 17 guests