Grid question ?

Hi.

From looking at the code, it seems the ObjectInCell and spawnTable aren’t getting cleared out, the former when you do onBtnRelease(), since that cell is being vacated, and the latter during a combine. So there may be some “ghosts” still there, giving you false positives.

Also, the onComplete listener will be provided the transitioned object as its parameter, so you don’t really have to do the loop in combineObjects(). Also, stationary objects might end up detecting “collisions” with themselves that way, i.e. object == other.

Other stuff:

You don’t need to nil object and other in combineObjects(). They’re just parameters, and will go away on their own.

You might have some luck just making spawnTable a group. Then you get management for free when you remove the objects (though this probably matters less in light of the onComplete note), though your tracker logic would be slightly different, say as spawnTable.numChildren - 1 and spawnTable.numChildren?

Since you know which column / row the balls will land on, you could just stash the respective numbers in each ball before its transition. Then you wouldn’t have to loop over all the columns and rows in combineObjects().

If I remove the loop with #spawnTable, the combination does not happen? The onComplete listener receives the transitioned object as its parameter as you said. How do I get the parameter’s row and col, without looping?

How do I go about “clearing out” ObjectInCell  and spawnTable? Not sure what you mean here.

I figure when you combine the two balls you don’t want them still affecting the world, say when you’re looping over them. That’s what I mean by clearing them out. If you just put the balls into a group, the removeSelf()'s will do this for you.

Clearing out ObjectInCell is the same idea. In my example code I did it in MoveObject(), whereas you’d probably do it in the button click (and move the local declaration before that, if it’s earlier in the file).

Actually, if I misunderstood you and only one of the two blobs will move, then you DON’T need to clear ObjectInCell (though I presume you would still want to switch the object).

That self-collision combination shouldn’t happen, no, once the objects are removing themselves from ObjectInCell, as well.

Since you know which ways the ball will split, you can just stuff the new column / row in the objects when you do your click, like Nick does above, then read them back in combineObjects(). Then when you add a new object, just set the new row / column relative to that one (and probably rewrite it in the other ball).

You could either start in a known position and assign the row / column that way (a fixed position, or assign the position itself from the column / row) or just compute them from your position and grid, like Prathap has done.

I keep thinking of this while reading the topic.  :slight_smile: Never did beat that one.