Shuffle Grid Demo

Drag & Drop the images to shuffle them around…

A friend of mine, Dale Sattler over at No Ponies recently posted a grid sorting class. He said it was based on my old dynamic stacking menu; but that was pure modesty as his script is based on a 2D grid and much more sophisticated.

Anyway – it inspired me to create a grid sorting / shuffling algorithm of my own. It behaves differently to Dales but I think it works pretty well.

The basic logic of the algorithm works by determining how far a dragged item travels along the grid (rows and columns) and then shuffling the surrounding items in the opposite direction by these values, therefore creating space for the dragged item to slot into when released.

It currently only works for grids which are fully populated, but adding more flexibility for incomplete grids will only be a matter of adding a few conditions – functionality which I’ll add when I get a moment.

You can extend the ShuffleGridItem class to add the functionality you need. In the demo I’ve made a simple image class which grabs a photo from Flickr.

Creating a ShuffleGrid is very simple, and can be done like so:

var grid:ShuffleGrid = new ShuffleGrid(4,7,40,40,1);

for (var i : int = 0; i < grid.numCells; i++)
{
	grid.addItem (new ShuffleGridItem());
}

addChild (grid);

The constructor takes the following arguments:

new ShuffleGrid(rows, cols, cellWidth, cellHeight, spacing);

Feel free to download the class and a simple demo and have a play around. I can imagine many uses for it, so hopefully it will come in handy.

Download: Shuffle Grid Class & Demo
Posted on 04 Mar 2009
40 Comments
6 Trackbacks

Meta

AS3 Shuffle Grid Class was posted on March 4th 2009 in the category Code / Actionscript 3.0, Code, Flash, Lab, Open Source and tagged; , , , , , , .

You can Leave a comment.

Twitter <follow>

February 8th 2010 - 1:28pm

@robgibo Ah, thats always going to hurt :)

Discussion

45 Responses to AS3 Shuffle Grid Class

Leave a Reply

Pingbacks / Trackbacks

  1. 11 months ago Bookmarks for March 5th from 15:03 to 15:06 « what i say // jon burger

    [...] AS3 Drag and Drop Shuffle Grid Menu Interface – [...]

  2. 8 months ago My First Game | PUBLIC SERVICE

    [...] soulwire’s Shufle Grid Class we present you PUZZLE NO [...]

  3. 8 months ago AntScript » 一个不错的效果收藏

    [...] 原文地址:http://blog.soulwire.co.uk/flash/flash-interfaces/as3-drag-drop-shuffle-grid-menu/#more-311 [...]

  4. 7 months ago Adobe — наш верный друг » AS3 Shuffle Grid Class — блог о air, flash, flex и других технологиях Adobe

    [...] делится своим видением области применения данной штуки. Можете поддержать [...]

  5. 2 weeks ago [Actionscript 3] Menu tipo iPhone con icone spostabili

    [...] ricerca.. ecco dove l’avevo visto noponies AS3 Drag Sort Grid Experiment e qui ce n’

  1. wilma j. hancock 3 months ago

    Hi just figured i would let you know i also had a problem with this blog appearing blank also. Might be monkeys in the system.

    Reply to this comment

  2. Rasterstudios 2 months ago

    Hey Soulwire , This site is awesome and you show a great programming stuff!! I can see a Pattern based oops in it..

    nJoy Coding!!

    To drewm ,

    It is not a bug, it does what he programmed… When you click and drag quickly, you may not know where your mouse pointer is.. If the mouse pointer is not pointing the SWF window, obviously the “Tile will be dropped”

    Reply to this comment

  3. jessicatv 2 months ago

    Thanks for this code, it’s very usefull

    Reply to this comment

  4. shifla 2 months ago

    hi mate, amazing work you have donde here! seriously!.
    hey, i was wondering how coul i put images inside each block, i really dunno how to do it, so any help would be great!!
    anyway,, congrats, great work mate.

    shif.

    Reply to this comment