How do I populate an scene with objects

Get help using Construct 2

Post » Thu Jun 30, 2016 6:53 am

Didn't get a chance to check out 99's solution since I'm not on latest beta, but here is one working to my satisfaction. It uses the spawn helper itself to check for open spaces around the blocks, then moves them to the correct image point.

https://www.dropbox.com/s/jy04myos0p47s ... .capx?dl=0

This bypasses the issue where adjacent collision boxes count as overlapping (the helper sprite is smaller than the block sprite), and you don't want to shrink the collision box on your block because you need it for your platforming behavior.

Pseudocode:

For each block, check if space above is empty with a helper.
If it is not empty, destroy helper sprite (and try next block).

ELSE if it is empty, destroy the helper above
Then make a new helper to the left of that block and pick all blocks to check collisions.
If collides, destroy that helper. Else, move it to the corner.

Repeat with a helper to the right of the block.


By the way, this should totally work if you manually set instance variables defining left/right corner, so I'm not sure if you're interested in troubleshooting why that wasn't working. The method I'm using right now is meant to save you the hassle of manually setting corners (as variables) in case you have a large level in the future.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Jun 30, 2016 12:29 pm

I tried a method similar to this one, funny thing in your capx file it works. Also 99's Solution works great although I would love to better understand the concept behind it.
Still, I have the same problem, helper still spawn on every corner. I did a check up of every thing that could be causing this but with no success. Instead of an animation frame, I created a new sprite to be used as corner and still same issues. It doesn't seem to recognize its overlapping another object.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Thu Jun 30, 2016 12:42 pm

Ok, update, seems to be on my side. I created two brand new sprites and there is no problem at all.
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Thu Jun 30, 2016 1:03 pm

Concept behind mine is ...

I used 4 helper objects, to check for overlaps. The reason why i use helper objects is that checking overlaps with the same instances of an object is a bit tricky. Should use families. oosyrag did not use a family, so i was like, wth, i not gooing to do it too.

Those helper objects (hor1 hor2 ver1 & ver2) have there origins set in a way that they overlap the questioned object and the object on the left, the right, on top and under. When i was dooing this, i found out that i dont need the 'under' for defining a rule, but i left it in there.

Now, when you place an object over other objects. And when you pick all objects that overlap that placed object, the expression object.PickedCount gives you the amount of objects that are overlapped. Including the questioned object.

So, in short, when i place the 4 helpers objects (in the for each loop) on the questioned object, i can according to how many objects this helper overlaps, make rules. And for this concept, there are only 2 rules needed, as you can see in the capx.

oosyrag does kinda the same, he is using the cornerobjects to dedect overlaps. So he's also not checking overlaps between instances of the same object, wich is as i said very tricky.
I was a bit suprised by his solution, but i did not understand his rules.

So i had to find them out, stronger then myself. But i am old school. So i need to see what i am dooing. And helper objects i can see. Now, at this moment, i know the rules, i could translate the idea to an array, or translate it to a loop in a tilemap, if i wanted to. But in the end, what i have given to you is for me the first step in solving things .. see what i do. I often use the tick-top-down-loop first, before making the real loop. Because that way i see, tick by tick, what i do. How it works, or actualy dont work at all. If it works, i bring it in the real loop.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 30, 2016 1:25 pm

Ah ok now I understand, thanks. For the other solution, object count was going insane, so I fixed it by adding on Start of Layout. I might go deeper into your solution after so I can have a better control ( and understanding) of it. I'm still trying to figure out why it worked with new sprites rather than old ones. had to adapt my events to it.

*Actually is because I set in the sprite properties Collision to Disabled, then it spawns helpers on every one of them since it no longer detects overlapping. I was using a small sprite of 4x4 pixels that I scale up to use as collision since it reduces collisions.
I'm going to try and adapt the same to this mask instead, or is there any better way to do this?
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Post » Thu Jun 30, 2016 2:42 pm

Each way is fine. By now you have seen that for each problem there are 50 solutions in C2.

Like using that simple 'On start of Layout'. I used to use that heavely. Now i rather use 'once while triggered'. In most circumstances, they do the same. But for me, the last one reads nicer, it wraps my head arround it in a better way.

That is usaly the factor that makes you choose for one or the other way the most. How it wraps your head arround it.

There is only 1 thing that you should avoid, (well a few more, but ... ) do not use collission/overlap conditions in big (nested) loops for many objects EACH TICK. That will bring the performans down.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 30, 2016 5:05 pm

FraktalZero wrote:Ah ok now I understand, thanks. For the other solution, object count was going insane, so I fixed it by adding on Start of Layout. I might go deeper into your solution after so I can have a better control ( and understanding) of it. I'm still trying to figure out why it worked with new sprites rather than old ones. had to adapt my events to it.

*Actually is because I set in the sprite properties Collision to Disabled, then it spawns helpers on every one of them since it no longer detects overlapping. I was using a small sprite of 4x4 pixels that I scale up to use as collision since it reduces collisions.
I'm going to try and adapt the same to this mask instead, or is there any better way to do this?


Right sorry about that, normally I would put something like this in a function to call on start of layout, or to update during runtime by trigger in case your blocks can move and you need to reposition the corner helpers.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Thu Jun 30, 2016 5:48 pm

Hey np guys, you helped me a lot!
Now I got to understand things a bit more. :)
B
43
S
12
G
14
Posts: 488
Reputation: 10,570

Previous

Return to How do I....?

Who is online

Users browsing this forum: NN81 and 24 guests