Copy link to clipboard
Copied
What I want to accomplish: when I drag the cursor over a sprite I want the sprite to break down and every single pixel moves through the screen at random x and y axis.
To make it simple the draw this is what I want but with much more fragments(pixels) around, thousands of them. How come could I approach this?
Thanks in advance.
Copy link to clipboard
Copied
if mc is the object whose pixels you want to randomize and display in a bitmap:
var bmpd:BitmapData = new BitmapData(mc.width,mc.height);
bmpd.draw(mc);
var bmp:Bitmap = new Bitmap(bmpd);
addChild(bmp);
mc.visible=false;
mc.addEventListener(MouseEvent.MOUSE_OVER,randomizeF);
function randomizeF():void{
var a:Array = [];
for(var x:int=1;x<=bmpd.width;x++){
for(var y:int=1;y<=bmpd.height;y++){
a.push(bmpd.getPixel32(x,y));
}
}
shuffle(a);
var i:int=0;
for(x=1;x<=bmpd.width;x++){
for(y=1;y<=bmpd.height;y++){
bmpd.setPixel32(x,y,a);
i++;
}
}
}
function shuffle(a:Array) {
var p:int;
var t:*;
var ivar:int;
for (ivar = a.length-1; ivar>=0; ivar--) {
p=Math.floor((ivar+1)*Math.random());
t = a[ivar];
a[ivar] = a
;
a
= t;
}
}
Copy link to clipboard
Copied
I think you're looking for MouseEvent.MOUSE_MOVE. Note there are lots of pixel manipulation examples at flashAndmath.com.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now