PDA

View Full Version : Object decomposition effect


blu3
03-20-2007, 12:00 AM
For example, i have an object (like square or something) and i need to animate it's decomposition and motion tween parts away What would be the best approach to do that? My idea was something like: if this object is an image, maybe there is a BitmapData method that allows me to cut off a certain part of it so that i can save that part as movie clip and then tween it away?

thanks

Flash Gordon
03-20-2007, 12:17 AM
easier to do for sure if the "objects" that fly away are rectangles. Seems like you have the right idea to me.

pixelwit
03-20-2007, 06:17 AM
Paste the following code into a new Flash file.

Click and drag to draw in the box in the top left corner.

Press any key to see the image copied into a grid of images.

The individual pieces of the image are then transformed separately.

//
//
import flash.display.*;
import flash.geom.Matrix;
//
//
lineStyle(1);
lineTo(200, 0);
lineTo(200, 200);
lineTo(0, 200);
lineTo(0, 0);
//
//
function createClipGrid(name, depth, rows, cols, bmp){
var clp = this.createEmptyMovieClip(name, depth);
var wi = bmp.width;
var hi = bmp.height;
var cellWi = wi/cols;
var cellHi = hi/rows;
var lastX = 0;
var lastY = 0;
var cWi = 0;
var goalX = 0;
var cHi = 0;
var goalY = 0;
var count = 0;
clp.allCells = [];
for(var i=0; i<cols; i++){
goalX = Math.round((i+1)*cellWi);
cWi = goalX - lastX;
for(var j=0; j<rows; j++){
count++;
goalY = Math.round((j+1)*cellHi);
cHi = goalY - lastY;
var trans = new Matrix();
trans.translate(-lastX, -lastY);
var cell = clp.createEmptyMovieClip("Cell"+i+"_"+j, count);
clp.allCells.push(cell);
cell.bmp = new BitmapData(cWi, cHi, bmp.transparent);
cell.attachBitmap(cell.bmp, 10, "never");
cell.bmp.draw(bmp, trans);
cell._x = lastX;
cell._y = lastY;
lastY = goalY%hi;
}
lastX = goalX%wi;
}
return clp;
}
//
//
function drawLine (){
lineTo(_xmouse, _ymouse);
}
onMouseDown = function(){
lineStyle(4, Math.random()*0xFFFFFF);
moveTo(_xmouse, _ymouse);
onMouseMove = drawLine;
}
onMouseUp = function(){
onMouseMove = null;
}
//
//
onKeyDown = function(){
var myBmp = new BitmapData(200, 200, false, 0xFFFFFF);
myBmp.draw(_root);
createClipGrid("CG", 20, 5, 8, myBmp);
CG._x = CG._y = 200;
for(var k in CG.allCells){
var c = CG.allCells[k];
c.xd = Math.random()*6-3;
c.yd = Math.random()*6-3;
c.onEnterFrame = tumble;
}
}
Key.addListener(this);
function tumble(){
with(this){
_x += xd;
_y += yd;
_yscale -= Math.random()*5;
_xscale -= Math.random()*5;
if(_xscale<0 || _yscale<0)removeMovieClip();
}
}
//
//

-PiXELWiT
http://www.pixelwit.com

blu3
03-20-2007, 09:48 AM
Thank you very much pixelwit, that's pretty close to what i am after for. I'll try to understand the code and adapt it