Flint Particle System Forum - How to explode stageWidth Image or Rectangle? Tue, 13 Dec 2011 01:00:54 +0000 http://flintparticles.org/forum/ Lussumo Vanilla 1.1.10 & Feed Publisher How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1340#Comment_1340 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1340#Comment_1340 Mon, 13 Sep 2010 17:25:54 +0100 mankica 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 ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1341#Comment_1341 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1341#Comment_1341 Mon, 13 Sep 2010 17:35:57 +0100 radykal

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);
]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1342#Comment_1342 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1342#Comment_1342 Mon, 13 Sep 2010 17:59:21 +0100 mankica 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. ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1343#Comment_1343 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1343#Comment_1343 Mon, 13 Sep 2010 18:01:14 +0100 mankica shape.graphics.drawRect(0, 0, 1100, 700);
and this is not working
shape.graphics.drawRect(0, 0, 1100, 800); ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1344#Comment_1344 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1344#Comment_1344 Mon, 13 Sep 2010 18:13:11 +0100 radykal
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. ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1345#Comment_1345 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1345#Comment_1345 Mon, 13 Sep 2010 18:42:13 +0100 mankica 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. ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1346#Comment_1346 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1346#Comment_1346 Mon, 13 Sep 2010 21:20:23 +0100 radykal
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. ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1347#Comment_1347 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1347#Comment_1347 Mon, 13 Sep 2010 21:48:43 +0100 mankica
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 );
} ]]>
How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1348#Comment_1348 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1348#Comment_1348 Mon, 13 Sep 2010 21:58:54 +0100 mankica How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1349#Comment_1349 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1349#Comment_1349 Tue, 14 Sep 2010 00:05:32 +0100 mankica How to explode stageWidth Image or Rectangle? http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1358#Comment_1358 http://flintparticles.org/forum/comments.php?DiscussionID=397&Focus=1358#Comment_1358 Thu, 16 Sep 2010 11:50:19 +0100 Richard
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. ]]>