Copy link to clipboard
Copied
Hi! I need some help understanding the way it can be done.
Lets say I have 2 objects a and b. If I want a to become b and b to become a I guess this is the way is done:
var temp_a:Object = a;
a = b;
b= temp_a;
This works perfectly fine with only 2 objects. The problem is when I am attempting to swap a with b, b with c and c with a.
Could please anyone help me make it through? If it does matter, I am working at a match 3 game where some rows are sliding left or right depending on a certain direction. It can go as a=c,c=b,b=a or a=b,b=c,c=a. I can make the gems swap positions correctly but as Objects, are the same as they were before.
Or:
var finalRollerTiles:Array = rollerElements;
var lastItem = finalRollerTiles[finalRollerTiles.length-1];
finalRollerTiles.pop();
finalRollerTiles.unshift(lastItem);
Copy link to clipboard
Copied
var temp_a:Object = a;
var temp_b:Object = b;
var temp_c:Object = c;
c = temp_b;
b = temp_a;
a = temp_c;
Copy link to clipboard
Copied
It would be silly of me to ask for help your answer would be the right one. Not that it isn't, but I still can't get it to work.
This would be my approach:
//create array to store tiles that move on grid;
var rollerTiles:Array = new Array();
for (var i:int = 0; i <= gridWidth - 1; i++)
{
for (var j:int = 0; j <= gridHeight - 1; j++)
{
if (tileVector
{
// tileVector
//if the in value is above 11 i'm storing my value in a new array.
rollerTiles.push(_gridArray
}
}
}
// since the above check does not find my values and an ascending order (in matrix), I need to sort them so I can tell wich item goes on wich position.
rollerTiles.sort(Array.NUMERIC);
var rollerElements:Array = new Array();
for ( var m:int = rollerTiles[0]; m <= rollerTiles[rollerTiles.length - 1]; m++)
{
for (var a:int = 0; a <= gridWidth - 1; a++)
{
for (var b:int = 0; b <= gridHeight - 1; b++)
{
if (tileVector!=null && _gridArray == m)
{
// now I'm pushing in the same order as the rollerTiles value, my objects into a new array.
rollerElements.push(tileVector);
}
}
}
}
// finally here I get to know that rollerElements[0] goes on the rollerElements[1], 1 on 2, 2 on 3, and so on....until the last one goes on 0.
for each rollerElements there is a real object equivalent to "tileVector
for ( var n:int = 0; n <= rollerElements.length - 1; n++)
{
if (n + 1 > rollerElements.length - 1)
{
TweenMax.to(rollerElements
}
else if (n + 1 <= rollerElements.length - 1)
{
TweenMax.to(rollerElements
}
}
// now that i moved them I need to tell them that they have to swap as objects.
//this part I can't get it through no matter what.
//creating an new array of objects, doesn't do the trick do.
var finalRollerTiles:Array = new Array()
finalRollerTiles.push(rollerElements);
var lastItem = finalRollerTiles[finalRollerTiles.length-1]
finalRollerTiles.pop();
finalRollerTiles.unshift(lastItem);
// here my arrays would look like this
//rollerElements, output ( 0,1,2,3....9)
// finalRollerTiles,output ( 9,0,1,2,....)
// sadly rollerElement[0]= finalRollerTiles[0] doesn't do the trick
Copy link to clipboard
Copied
finalRollerTiles.push(rollerElements);
You're pushing all the array inside another one, so you'll get one element only as an array..
you have to push the elements using for loop:
var finalRollerTiles:Array = new Array();
for (var f:int = 0; f<rollerElements.length; f++)
{
finalRollerTiles.push(rollerElements
}
var lastItem = finalRollerTiles[finalRollerTiles.length-1];
finalRollerTiles.pop();
finalRollerTiles.unshift(lastItem);
Copy link to clipboard
Copied
Or:
var finalRollerTiles:Array = rollerElements;
var lastItem = finalRollerTiles[finalRollerTiles.length-1];
finalRollerTiles.pop();
finalRollerTiles.unshift(lastItem);
Copy link to clipboard
Copied
Hi there! Thanks a lot for your help. I figure that "finalRollerTiles" it isn't enough to do the job. Made one more similar array but instead of pop() and unshift() I used shift() and then push. First array goes for each object's coordinates and the second one goes for swapping objects.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now