Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to add Event to every single pixel with BitmapData?

Community Beginner ,
May 09, 2014 May 09, 2014

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?

simple.png

Thanks in advance.

TOPICS
ActionScript
239
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 09, 2014 May 09, 2014

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;

    }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
May 10, 2014 May 10, 2014
LATEST

I think you're looking for MouseEvent.MOUSE_MOVE. Note there are lots of pixel manipulation examples at flashAndmath.com.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines