Fork me on GitHub
Not signed in (Sign In)

Welcome, Guest

Want to take part in these discussions? Sign in if you have an account, or apply for one below

    • CommentAuthorjbitautas
    • CommentTimeApr 14th 2011
     
    Is it possible to use MouseAntiGravity on a PixelRenderer? I'm working on a project similar to the logo example on the homepage, but I want the pixels to get "pushed" away from the mouse when moused over. Is this possible? I think my code is correct, but the mouse over does nothing. Here's my code:


    var glassImage:BitmapData = new GlassImage ( 100, 250 );
    var tween2Emitter:Emitter2D = new Emitter2D();
    var renderer:PixelRenderer = new PixelRenderer( new Rectangle( 0, 0, 400, 200 ) );
    addChild( renderer );
    setChildIndex (renderer, 0);

    tween2Emitter.addInitializer( new Lifetime( 6 ) );
    tween2Emitter.addAction( new Age( Quadratic.easeInOut ) );
    tween2Emitter.addAction( new TweenToZone( new BitmapDataZone( glassImage, 40, 60 ) ) );
    tween2Emitter.addAction( new RandomDrift( 20, 20 ) );
    tween2Emitter.addAction( new MouseAntiGravity(10,renderer) );

    renderer.addFilter( new BlurFilter( 2, 2, 1 ) );
    renderer.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0.97,0 ] ) );
    renderer.addEmitter( tween2Emitter );

    startEmitter.start();
    tween2Emitter.start();


    Thanks
    • CommentAuthorjbitautas
    • CommentTimeApr 15th 2011
     
    So I've taken a different approach from the code above and did get the pixel rendererer working as expected with the MouseAntiGravity function with a Pulse emitter. Now I'm trying to figure out if it's possible to have the MouseAntiGravity function working with the TweenToZone. I'm using a removeAction on the emitter in a MouseEvent on hit area covering the stage and then adding MouseAntiGravity, but it's not working as I expected. The trace registers, but the rest of the code doesn't seem to work. Perhaps I'm not using the removeAction correctly or is it not possible to remove the TweenToZone action? Here's my code:

    hit.addEventListener (MouseEvent.ROLL_OVER, antiGrav);

    private function antiGrav (event:MouseEvent):void {

    startEmitter.removeAction (new TweenToZone (new BitmapDataZone (glass)));
    tween1Emitter.removeAction (new TweenToZone (new BitmapDataZone (copy1)));
    tween2Emitter.removeAction (new TweenToZone (new BitmapDataZone (glass)));
    antiGravity = new MouseAntiGravity (10, renderer);
    startEmitter.addAction (antiGravity);
    trace ("HIT");
    }

    Thanks
    • CommentAuthorjbitautas
    • CommentTimeApr 15th 2011
     
    I've managed to get MouseEvent to work with MouseAntiGravity on mouse click for particles in the TweenToZone without having to use a hit area clip as I mentioned above. I did however have to surround the renderer in a MovieClip to add it to Flash's display list to utilize an event listenener on it. My new issue is the renderer is the whole visible stage area, so when I click on top of the Zone particles it doesn't disrupt only the particles that are under the mouse, rather they are all affected, making it look more like an explosion rather than the mouse anti-gravity effect I'm going for. Any thoughts? Thanks
    • CommentAuthorjbitautas
    • CommentTimeApr 15th 2011
     
    Also, for a little bit more clarification on what I'm trying to do, I'm looking for each particle to be affected by the mouse over rather than the whole renderer. Meaning the particle itself has a hit area perhaps? Thanks again
    • CommentAuthorRichard
    • CommentTimeApr 20th 2011
     
    Hi

    You can't combine physics based actions like MouseAntiGravity, with literal actions like TweenToZone because the literal action ignores the physics and sets the particle position where it thinks it should be regardless. You could try some other method to move the particles towards their destination or create a custom renderer along the lines of the TweenToZone but using physics (maybe use the destination in the zone as a gravity well for that particle rather than a literal tween destination).

    For the mouse events, the renderer has its mouseEnabled and mouseChildren set to false by default. If you set the mouseEnabled to true you won't need to wrap the renderer in a movie clip.

    You can only get mouse events on specific particles if you use the DisplayObjectRenderer (and set mouseChildren to true), because this is the only renderer in which the particles are rendered as discrete display objects - the BitmapRenderer and PixelRenderer render all the particles in a single Bitmap object.

    Hope that helps. Sorry you had to wait a while for a reply.