Hi,
I am making a puzzle type game where the aim is to match tiles. It is currently working by adding the tiles to a static group once they have collided with either the existing static group (which I call the stack) or the floor.
I have a method which re-aligns the stack by looping through each column and shifting the position of the tile down if a gap is detected. This is working, only it appears that the static group’s collision domain remains as it was, even though there is no tile present where it has been shifted. If I dump the stack sprite group to the console, I can see that only six tiles exist in the example, only the debugging shows that there are more.
Here is the code:
function realignStack(thisscene) {
var gapdetected = false;
var destroySet = [];
for (var i = 0; i < 840; i+= 60) {
//Get column
var c = stack.children.entries.filter(child => child.x == i);
var col = [...c];
col.sort(function(a, b){return b.y - a.y});
if(col.length > 0) {
var j = 540;
var k = 0;
var minsize = Math.min.apply(Math, col.map(function(t) { return t.y; }));
while(j > minsize) {
if(col[k].y != j) {
gapdetected = true;
col[k].setPosition(col[k].x,j);
minsize = Math.min.apply(Math, col.map(function(t) { return t.y; }));
}
j -= 60;
k++;
}
if(gapdetected) {
console.log(stack);
thisscene.pause();
gapdetected = false;
}
col = [];
}
}
}