Prerequisites
- You should be familiar with OOP concepts and AS3
- Basic knowledge about Away3D (primitives, materials, cameras…)
The code (SlidingPuzzle.as)
So let’s see how it is done. First we’ll take a closer look at the main class (SlidingPuzzle.as). To get things working we need to import the proper classes.
package { import away3d.cameras.HoverCamera3D; import away3d.containers.View3D; import com.techlabs.puzzle.ControlPanel; import com.techlabs.puzzle.PuzzleBoard; import com.techlabs.puzzle.events.PuzzleEvent; import com.techlabs.puzzle.helpers.ImageSlicer; import flash.display.Bitmap; import flash.display.Loader; import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageQuality; import flash.display.StageScaleMode; import flash.events.Event; import flash.net.URLRequest;
Next we initialize the variables.
public static var subdivisions:int = 4;
Subdivisions determine how the puzzle board and the image itself are divided into smaller pieces. The default value results in 16 pieces.
public static var padding:int = 2;
Padding defines the gap between puzzle pieces.This gives our game a bit more realistic feel.
public static var size:int = 500;
Size determines the physical dimensions of the puzzle board. The loaded image doesn’t have to be 500x500px but make sure it is not too small either. Bigger is better