• (3 Pages)
  • +
  • 1
  • 2
  • 3

Sliding Puzzle Game Using classes and AS2 Rate Topic: ***** 2 Votes

#16 thehat  Icon User is offline

  • awake ? web();
  • member icon

Reputation: 106
  • View blog
  • Posts: 951
  • Joined: 28-February 08

Posted 21 January 2009 - 08:48 AM

Ha, it's still my badly written tutorial that's at fault! In the createTiles method of the bitmapGenerator, where it loops though the image dividing it into rectangles, the bitmapArray is being reset every time a new row is started. This is the correct method, with the change marked with a comment.

public function createTiles(clipRef:String, totW:Number, totH:Number, tileX:Number, tileY:Number):Array {

	trace("creating bitmaps");

	var mainImage:BitmapData = BitmapData.loadBitmap(clipRef);

	tileW = mainImage.width/tileX;
	tileH = mainImage.height/tileY;
		
	bitmapArray = new Array();
	for (var i:Number = 0; i<tileX; i++) {

		bitmapArray[i] = new Array();  // ***** This line was missing a [i]

		for (var n:Number = 0; n<tileY; n++) {
			var tempData:BitmapData = new BitmapData(tileW, tileH);
			var tempRect = new Rectangle((tileW*i), (tileH*n), tileW, tileH);
			tempData.copyPixels(mainImage,tempRect,new Point(0, 0));
				
			bitmapArray[i][n] = tempData;
		}
	}
		
	return bitmapArray;

}



Sorry for the hassle, and for the badly written tutorial :rolleyes:
Was This Post Helpful? 0
  • +
  • -

#17 kaira_e  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 20-January 09

Posted 21 January 2009 - 09:00 AM

I copy pasted the code from above.
The image does show now, but the pieces don't stay inside of the rectangle....
I made a screenshot of this.

Attached Image

I'm sorry to keep bothering you with this XD;
Was This Post Helpful? 0
  • +
  • -

#18 JamesU2002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 12-February 09

Posted 12 February 2009 - 09:05 AM

The problem comes when you change the number of finishes above 10.

Hopefully, thehat can help?
Was This Post Helpful? 0
  • +
  • -

#19 gth747y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 09

Posted 10 June 2009 - 10:45 PM

I found an error in the slidingPuzzleMain class that once fixed does the trick and the game works.

go to the createTiles() method

in the first for loop (for every tile on the x axis), the y axis arrays are not initalized correctly. Basically it was just re-initializing the tiles array over and over.

Also, at the end of the createTiles() method, there is a call to jumble(). Thats all good, but there is a method that needs to be called before that to enable all the movie clips. resetPuzzle() calls jumble() and also enables the movie clips, so I replaced jumble with resetPuzzle.

 private function createTiles():Void {
				
				var tileID:Number = 0;
				
				tiles = new Array();
				//for every tile on the x axis
				for (var i:Number = 0; i < tilesX; i++) {
						
					   /***REPLACE ORIGINAL LINE WITH THIS ONE****/
					   tiles[i] = new Array();
					   
					   //for every tile on the y axis
						for (var n:Number = 0; n < tilesY; n++) {
								
								var tempMC:MovieClip = this.createEmptyMovieClip("tile"+tileID,this.getNextHighestDepth());
							tiles[i][n] = new  slidingPuzzleTile(tempMC,bitmaps[i][n],tileID,i,n,borderCol,borderWidth,borderAlpha);
								tiles[i][n].addEventListener("onTileClicked",this);
								tempMC._x = tempMC._width * i;
								tempMC._y = tempMC._height * n;
								tileID++;
								
						}
						
				}
				
				// remove the last tile to create the required empty square
				tiles[tiles.length-1][tiles[tiles.length-1].length-1].targMC.removeMovieClip();
				tiles[tiles.length-1][tiles[tiles.length-1].length-1] = "empty";
				
				//jumble and reset the puzzle
				resetPuzzle();
				
		}


This post has been edited by gth747y: 10 June 2009 - 10:48 PM

Was This Post Helpful? 0
  • +
  • -

#20 nehalacharya  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 19-June 09

Posted 19 June 2009 - 09:58 PM

Hi

Have tried this tutorial it works but the pic doesn't get jumbled

can U help me out

Am attaching the zip fileAttached File  dreamcode.zip (102.31K)
Number of downloads: 1270
Was This Post Helpful? 0
  • +
  • -

#21 gth747y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 09

Posted 10 July 2009 - 05:36 AM

View Postnehalacharya, on 19 Jun, 2009 - 08:58 PM, said:

Hi

Have tried this tutorial it works but the pic doesn't get jumbled

can U help me out

Am attaching the zip fileAttachment attachment


Check out my reply 1 post above yours. It fixes that problem.

There still exists a problem where sometimes the jumbling will cause a piece to fly off the page, but I haven't figured that one out yet.
Was This Post Helpful? 0
  • +
  • -

#22 ziik  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-August 09

Posted 15 August 2009 - 12:18 AM

:blink:

Hey there.

Im using flash CS4, im not entireely sure how to make that empty movie clip to a component and get the parameters?

when i right click on puzzle, then go to properties then click "export for actionscript" and then i want to place the "com.slidingPuzzleMain" in class, it wont let me and it says that i need to do it in AS3. but i really need to do this in AS2.

a little help please?

thanks.
Was This Post Helpful? 0
  • +
  • -

#23 gth747y  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-June 09

Posted 24 August 2009 - 04:49 AM

View Postziik, on 14 Aug, 2009 - 11:18 PM, said:

:blink:

Hey there.

Im using flash CS4, im not entireely sure how to make that empty movie clip to a component and get the parameters?

when i right click on puzzle, then go to properties then click "export for actionscript" and then i want to place the "com.slidingPuzzleMain" in class, it wont let me and it says that i need to do it in AS3. but i really need to do this in AS2.

a little help please?

thanks.


If you edit your document publishing properties, you can change the ActionScript version to 2.0. In CS4 goto to File > Publish Settings > and there should be a tab that will take you to the ActionScript version.
Was This Post Helpful? 0
  • +
  • -

#24 mastercute  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-December 09

Posted 01 December 2009 - 11:04 PM

View Postgth747y, on 10 Jul, 2009 - 04:36 AM, said:

View Postnehalacharya, on 19 Jun, 2009 - 08:58 PM, said:

Hi

Have tried this tutorial it works but the pic doesn't get jumbled

can U help me out

Am attaching the zip fileAttachment attachment


Check out my reply 1 post above yours. It fixes that problem.

There still exists a problem where sometimes the jumbling will cause a piece to fly off the page, but I haven't figured that one out yet.


It is the function Tween() which cause the problem

Call Disablebuttons() before jumble()

Then bypass function Tween() in doTween() by checking targMC.enabled
Was This Post Helpful? 0
  • +
  • -

#25 Guest_albert*


Reputation:

Posted 03 March 2010 - 05:32 PM

Hello Mastercute,

Can you explain a little bit how to fix this bug???

I try with move_to_finish = 8 and some of times is ok, but sometimes 2 tiles move to the same space!!!!

Thanks

Albert
Was This Post Helpful? 0

#26 Guest_tenchi*


Reputation:

Posted 12 August 2010 - 04:18 PM

I got the same issue too. there are chances that 2 block will end up in the same place.
Was This Post Helpful? 0

#27 Guest_lafrae*


Reputation:

Posted 19 August 2010 - 03:38 AM

Hi everybody,

I'm sorry but I can't fix the bug to jumble the tiles. Did anybody fix it?

Thanks !
Was This Post Helpful? 0

#28 Guest_chrism*


Reputation:

Posted 16 September 2010 - 09:05 AM

I'm having the same issue with this.. I really want to give the puzzle 100 moves to complete but it goes mad and puts too many white spaces and puts slides ontop of each other... has anyone worked out why?
Was This Post Helpful? 0

#29 Guest_kaiserjoint*


Reputation:

Posted 28 December 2010 - 03:15 AM

Fix it! mostly :P there are a few restrictions for all of this...

The fix:
inside 'slidingPuzzleMain.as' in the jumble function there is a piece of code creating a random number.
The problem was the "possibles.length".
I traced this and it gave different numbers each time.

I changed it and now it works great.


var randNum:Number = Math.floor(Math.random() * (possibles.length));
into >>>> var randNum:Number = Math.floor(Math.random() * 1);

The restrictions involving this script.
Pay attention to the amount of moves_to_finish in relation to the amount of tiles you use.
It's spacing out if you use for example: a 3x3 puzzle with a moves_to_finish of 100.
I'd say just keep it realistic.
Was This Post Helpful? 0

#30 Guest_Ledrer copy,*


Reputation:

Posted 29 December 2010 - 07:01 AM

this will only make a small shuffle still working on the real solution..

View Postkaiserjoint, on 28 December 2010 - 02:15 AM, said:

Fix it! mostly :P there are a few restrictions for all of this...

The fix:
inside 'slidingPuzzleMain.as' in the jumble function there is a piece of code creating a random number.
The problem was the "possibles.length".
I traced this and it gave different numbers each time.

I changed it and now it works great.


var randNum:Number = Math.floor(Math.random() * (possibles.length));
into >>>> var randNum:Number = Math.floor(Math.random() * 1);

The restrictions involving this script.
Pay attention to the amount of moves_to_finish in relation to the amount of tiles you use.
It's spacing out if you use for example: a 3x3 puzzle with a moves_to_finish of 100.
I'd say just keep it realistic.

Was This Post Helpful? 0

  • (3 Pages)
  • +
  • 1
  • 2
  • 3