PDA

View Full Version : PixelMover class - explode & contract pixels and stuff



tylerdudley1986
October 19th, 2007, 01:47 PM
Hello, not sure if anyone has done stuff like this before, so thought I would post it and see what people think.

Try it:
http://flash.sitdap.com/pixelmover

Download source:
44415

...you create an instance of pixelmover, and give it a sprite with any graphics in.

methods:

spreadPixels(maxRadius:int) - maxRadius default value is 200
- will randomly splay the pixels of your given sprite about the place, staying within the maximum radius
movePixels(speed:int) - speed default is 6, lower is faster.
- at the moment, all this does is move back the pixels to their original position, then when they arrive it fades back to the original bitmap and removes itself from its parent. When it is all done, it dispatches an event called "PIXELS_MOVED".

so this is how I would use it:



var myPixelMover:PixelMover = new PixelMover(mySprite);
myPixelMover.spreadPixels(100);
addChild();
myPixelMover.addEventListener("PIXELS_MOVED", moveHandler);
myPixelMover.movePixels(4);

function moveHandler(evt:Event) {
trace("the pixels are back where they were")
}
..It should adapt to any size you make your sprite, but I fear about performance issues with so many pixels and all.
Comments are welcomed - bad or good as I don't know whether everything is fully efficient as it could be. Feel free to add to it if you think it needs something!

cheers,
TD

tylerdudley1986
October 19th, 2007, 02:00 PM
sorry - forgot to mention this is in AS3.

prg9
October 19th, 2007, 02:44 PM
That looks pretty neat, (wish it was Flash 8 AS2, any chance of that ? For all of use still back in time ;-) Nice work tylerdudley1986! Thanks for sharing.

digitaldivide
October 21st, 2007, 07:30 AM
Same over here... But it is really cool! Really cool...

tezzutezzu
October 21st, 2007, 01:27 PM
Hey tyler! good job! I was thinking to do something like this to test the bitmap getPixel() method but then I was dragged by another thing.
To make it move also in the beginning (like an explosion) you might store a public destX and destY variable in the MoveablePixel class and then use these in your tweening functions.
At a first glance I don't get why you used timer functions for the movement (is it for boosting framerate?). I'm going to check them again though.

Anyway thanks a lot for sharing

tylerdudley1986
October 21st, 2007, 03:42 PM
Thanks, yeah tezzutezzu good idea I was thinking of putting extra stuff like that into it aswell... Don't know about the timer thing, I guess I just wanted to keep it independant of the frame rate for flexibility, and I think I read somewhere that timer is better for resources? maybe not true though, someone back me up or correct me!!!
I'll try and convert over to AS2, but it feels really old now... even though I've only been on AS3 for a couple of weeks now! Also I don't know whether AS2 could handle this without ByteArray. I'll give it a go anyways.

Cheers! TD

vini
October 22nd, 2007, 05:24 PM
great stuff Dude.. thanks

sietjp
February 16th, 2008, 06:23 AM
An old thread but a great class, thank you for sharing!

minthu
February 17th, 2008, 03:38 AM
oh! interesting stuff... to check out. :drool:

randomagain
February 20th, 2008, 05:45 AM
nice job,

coreman2200
February 28th, 2008, 03:51 AM
Dude that is an Incredibly sick effect! And it works so smoothly that it just looks that much more awesome lol. I haven't checked out the code yet (I am interested though, so I will), but I have the question; do you think that the effect could be pulled off with dynamic or user-input text? Or what about adding effects To that? Like swirls or zigzags via sin/cos functions? Or would that kill running speed with slowdown n such?