-
lemon juice hurts your eyes
Shuffle array/tile container problem
Hi all,
I'm working on an assignment for school right now, and what I'm making is one of those "tile puzzles", you know, with one blank tile.
Now I've made an illustration in Illustrator, imported it, made it into a movieclip and then I slice it up with actionscript, put the pieces into an Array and add them to a container.
The code to scramble the Array when the user presses the play button is:
Code:
function randomize():void
{
tileArray = tileArray.sort(shuffle);
xCounter = 0;
yCounter = 0;
for (var i:uint = 0; i<container.numChildren-1; i++)
{
tileArray[i].x = xCounter*100;
tileArray[i].y = 24 + yCounter*100;
if (xCounter+1 < 10)
{
xCounter++;
}
else
{
xCounter = 0;
yCounter++;
}
}
}
function shuffle(a,b):int
{
var num:int = Math.round(Math.random()*2)-1;
return num;
}
Now, the code I'm using when slicing the image and placing it at it's default position also sets the alpha of the first tile (0,0) to 0, thus leaving the blank space.
When I click the stage, the array is shuffled and the container rearranged. But there's this one problem: a new blank space appears.
And you can't have a decent game like this one with two blank spaces, now can you
I appreciate any kind of help
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
Make sure you reset the alpha of all the tiles to 1 at the start of the shuffle.. ?
-
lemon juice hurts your eyes
Well, I managed to solve it by changing the "i<container.numChildren-1" to "i<container.numChildren".
The extra blank space was just caused because one of the tiles isn't moved around..
But I have a question, maybe someone can help me with that.
It's a slide puzzle, so when the user clicks a tile, it is supposed to check if there's a blank space in one of the four directions and if so, that it's directly next to it.
How can I accomplish this?
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
lemon juice hurts your eyes
Okay, I was searching for solutions inside of the help file > DisplayObjectContainer when I found the getObjectsUnderPoint method.
I tried using this to check if there was a tile behaving as empty 100px to the left/right/top/bottom of the clicked tile.
And with succes, it does see the object, or the bitmap that is, but I can't use it, since I'm working with a Tile class.
So is there a way to convert the bitmap to a tile object?
I tried this:
Code:
Tile(DisplayObjectContainer(parent).getObjectsUnderPoint(new Point(DisplayObjectContainer(parent).mouseX - 100,DisplayObjectContainer(parent).mouseY))[0]).getIsBlank());
Which returns me "cannot convert Bitmap to Tile" ..
I need to use the getIsBlank() method of the Tile objects in order to see if they are blank or not, so this is the vital part of the puzzel game ..
Where are all you brainy guys with your crazy solutions?
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
-
lemon juice hurts your eyes
Florian Vanthuyne
WAR AGAINST SOLVED THREADS
mark yours as Resolved under Thread Tools!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|