CMS
CMS

Reputation: 706

Game Solution ActionScript 3

i am makin a puzzle game in as3 and I am allready done. i splitted a bitmap into 8 parts, I converted them into mc's and I am able to move them around with the mouse.

I made a puzzleboard too where the puzzle pieces are droped. now how can I make a puzzle solution, like when the puzzle pieces are in the right order then the whole bitmap should be displayed.

thak you for your attention

Upvotes: 1

Views: 260

Answers (1)

PatrickS
PatrickS

Reputation: 9572

Why don't u store the mcs positions in an Array of Points?

This way , wherever the mcs are on the board , it would be easy to tween them back into position.

 var positions:Array = [ new Point(mc1.x , mc1.y), .... , new Point(mcn.x , mc1.n), ];

 //assuming that this code is run from 
 // the mcs container and that this container
 // doesn't have any other children
 for( var i:int ; i < this.numChildren ; ++i )
 {
     //provided that the MCs are on 
     //the right order in the Display List
     var mc:MovieClip = this.getChildAt(i) as MovieClip;

     //no tween here but you get the idea...
     mc.x = positions[i].x; 
     mc.y = positions[i].y; 
 }

After you split the bitmaps and transfom them into MovieClips, I assume that at that stage you have the solution of the puzzle.

If yes, you then need to store the current positions of the pieces before they had a chance to be moved.

Practically that means not adding an event listener before you've actually stored the positions.

 //instantiate the Array
 var positions:Array = [];
 for(var i:int ; i < this.numChildren; ++i )
 {
    // add the mcs positions
    var positions[i] = new Point ( this.getChildAt(i).x , this.getChildAt(i).y );

    //you could add your Mouse Event listener here...
 }

Upvotes: 1

Related Questions