A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Shuffle array/tile container problem

  1. #1
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546

    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!

  2. #2
    Senior Member
    Join Date
    May 2001
    Location
    London
    Posts
    331
    Make sure you reset the alpha of all the tiles to 1 at the start of the shuffle.. ?

  3. #3
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    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!

  4. #4
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    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!

  5. #5
    lemon juice hurts your eyes florianvanthuyn's Avatar
    Join Date
    Jul 2005
    Location
    Merelbeke, Belgium
    Posts
    546
    No one?
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center