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

    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    This particle system is so great. I'm trying to learn how to use it.
    I have tried explode image example to explode image that has same width and height as stage. Actually I just need white empty page that will explode. But I don't know how to change size of the image inside the code. So I made some big white image in Photoshop. About 1280pxX1024px but when the image is that big I get error
    ArgumentError: Error #2015: Invalid BitmapData.
    Is there a way to create big white rectangle of that size that will explode?
    Thank you
    • CommentAuthorradykal
    • CommentTimeSep 13th 2010
     
    Yes very easy.


    var shape:Shape = new Shape();
    shape.graphics.beginFill(0xFFFFFF);
    shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    shape.graphics.endFill();

    var bmd:BitmapData = new BitmapData(shape.width, shape.height);
    bmd.draw(shape);
    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    Thank you for your answer. But I have the same problem. When I put 500, 400px like this
    shape.graphics.drawRect(0, 0, 500, 400);
    it's working. But with stage.stageWidth, stage.stageHeight dimensions I get the same error:
    ArgumentError: Error #2015: Invalid BitmapData.
    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    Also this is working
    shape.graphics.drawRect(0, 0, 1100, 700);
    and this is not working
    shape.graphics.drawRect(0, 0, 1100, 800);
    • CommentAuthorradykal
    • CommentTimeSep 13th 2010
     
    Then your stage is null.

    You can check this by tracing your stage. Do this:

    trace(stage);

    If it´s null, you have to set a Added_To_Stage listener.
    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    I just added this for testing.
    After :
    addChild( renderer );
    emitter.start();

    I added:
    renderer.addEventListener(Event.ADDED_TO_STAGE, added);
    function added():void {
    trace(stage.stageWidth);
    }

    But it doesn't run, like is not added to stage. Where do I need to put that ADDED_TO_STAGE listener?

    Sorry for so many questions.
    • CommentAuthorradykal
    • CommentTimeSep 13th 2010
     
    Not the renderer, the stage:

    stage.addEventListener(Event.ADDED_TO_STAGE, added);


    But honestly these are beginner questions and you want to use a particle engine??! You should learning more the basic stuff of AS3 instead of using a particle engine, which is more for advanced developers.
    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    stage.addEventListener(Event.ADDED_TO_STAGE, added); is first that I have tried and it didn't work.

    Sorry again that I have made a beginer question, I just recently turn to AS3. And when some things don't work as they should I start to be confused and do crazy stuff. (Learning harder because english is not my native language, and there are no books on my language).

    Here is the full code. It's code from image explode example, I just added my modification, but it won't work.
    If someone can make it work great, if not thank you for your time, I know that you are not obligated to answer my question, and I'm very grateful you did so far.


    /*
    * FLINT PARTICLE SYSTEM
    * .....................
    *
    * Author: Richard Lord
    * Copyright (c) Richard Lord 2008-2010
    * http://flintparticles.org/
    *
    * Licence Agreement
    *
    * Permission is hereby granted, free of charge, to any person obtaining a copy
    * of this software and associated documentation files (the "Software"), to deal
    * in the Software without restriction, including without limitation the rights
    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    * copies of the Software, and to permit persons to whom the Software is
    * furnished to do so, subject to the following conditions:
    *
    * The above copyright notice and this permission notice shall be included in
    * all copies or substantial portions of the Software.
    *
    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    * THE SOFTWARE.
    */
    import flash.display.*;
    import org.flintparticles.twoD.actions.*;
    import org.flintparticles.twoD.emitters.Emitter2D;
    import org.flintparticles.twoD.particles.Particle2DUtils;
    import org.flintparticles.twoD.renderers.*;
    import org.flintparticles.twoD.zones.*;
    import org.flintparticles.common.initializers.*;
    import org.flintparticles.common.actions.*;
    import fl.motion.easing.*;

    var bitmapData1:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFF00);
    var txt:TextField = new TextField();
    txt.autoSize = TextFieldAutoSize.LEFT;
    var tf:TextFormat = new TextFormat();

    var emitter:Emitter2D = new Emitter2D();
    var shape:Shape = new Shape();
    shape.graphics.beginFill(0xFFFFFF);
    shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    shape.graphics.endFill();

    var bmd:BitmapData = new BitmapData(shape.width, shape.height);
    bmd.draw(shape);

    var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData( bmd, 10, emitter.particleFactory, 100, 0 );
    emitter.addExistingParticles( particles, false );

    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    renderer.addEmitter( emitter );
    addChild( renderer );
    emitter.start();



    stage.addEventListener(Event.ADDED_TO_STAGE, added);
    stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );
    function added():void {
    trace(stage.stageWidth);
    }
    function explode( ev:MouseEvent ):void {


    var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );

    emitter.addAction( new Explosion( 10, 640, 340, 600 ) );

    emitter.addAction( new Move() );
    emitter.addAction( new DeathZone( new RectangleZone( -10, -10, stage.stageWidth+10, stage.stageHeight+10 ), true ) );

    stage.removeEventListener( MouseEvent.CLICK, explode );
    }
    • CommentAuthormankica
    • CommentTimeSep 13th 2010
     
    Just to mention, code works if the stage width and height are smaller or equal 1100x700px, otherwise it does not, even crashes flash
    • CommentAuthormankica
    • CommentTimeSep 14th 2010
     
    Found the problem. When rectangle particels are too small flash crashes.
    • CommentAuthorRichard
    • CommentTimeSep 16th 2010 edited
     
    Hi mankica

    You can simplify your code. This should work...

    var bitmapData1:BitmapData = new BitmapData(stage.stageWidth, stage.stageHeight, true, 0xFFFFFFFF);

    var emitter:Emitter2D = new Emitter2D();

    var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData( bitmapData1, 10, emitter.particleFactory, 0, 0 );
    emitter.addExistingParticles( particles, false );

    var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
    renderer.addEmitter( emitter );
    addChild( renderer );
    emitter.start();

    stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );

    function explode( ev:MouseEvent ):void {
    var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );
    emitter.addAction( new Explosion( 10, 640, 340, 600 ) );
    emitter.addAction( new Move() );
    emitter.addAction( new DeathZone( new RectangleZone( -10, -10, stage.stageWidth+10, stage.stageHeight+10 ), true ) );
    stage.removeEventListener( MouseEvent.CLICK, explode );
    }


    This works for me (if a little slowly) at 2560 x 2048. When I double the size again to 5160x4096 it doesn't work. I don't get an error but Flash player just grinds to a halt.

    At what point Flash can't cope will depend on the particular computer and the version of the Flash player. As you note, making the rectangle particles bigger reduces the number of rectangles and so improves performance.