Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>So i put together a solution for my question with the help of Andreas and adamh.</p> <p>Andreas - showed me that i forgot to dispose the bitmapdata (really nice spot!)</p> <p>Adamh - told me to define scrollrect on the canvas (Upped the performance a lot!)</p> <p>But what did it in the end and made the performance fluid, was a simple mistake from my side. I noticed in the particle.as > render(), that i was only checking if the particle was out of bounds on 2 sides (facepalm), stupid mistake. When i changed the render function to check the remaining 2 sides, it fixed the performance issue.</p> <p>Sorry for the stupid question :) and thanks again to Andreas and adamh</p> <p>the final classes:</p> <p><strong>FluidLayer.as</strong></p> <pre><code>package { import flash.display.Sprite; import flash.events.MouseEvent; import flash.display.BitmapData; import flash.filters.BlurFilter; import flash.display.Bitmap; import flash.geom.Point; import flash.geom.ColorTransform; import flash.display.IBitmapDrawable; import flash.events.Event; import flash.display.MovieClip; import flash.geom.Rectangle; public class FluidLayer extends MovieClip { private var canvas:Sprite; private var b:Bitmap; private var blur:BlurFilter = new BlurFilter(20,20,3); private var bmd1:BitmapData; public function FluidLayer() { canvas = new Sprite(); canvas.scrollRect = new Rectangle(0,0,1010,550); for(var i:int = 0;i &lt; 600;i++){ var p:Particle = new Particle(); canvas.addChild(p); p.x = stage.stageWidth * Math.random(); p.y = stage.stageHeight* Math.random(); p.initi(stage); } canvas.filters = new Array(blur); addEventListener(Event.ENTER_FRAME, render); } private function render(e:Event):void{ remove(); b = new Bitmap(makeFluid(canvas),"auto", true); b.alpha = 0.7; addChild(b); } private function makeFluid(o:Sprite):BitmapData{ bmd1 = new BitmapData(stage.stageWidth, stage.stageHeight, true); bmd1.draw(o,null,null,null,null,true); bmd1.threshold(bmd1, bmd1.rect, new Point(0,0), "&gt;", 0XFF2b2b2b, 0x55FFFF, 0xFFFFFF, false); return bmd1; } private function remove():void{ if(numChildren &gt; 1) removeChildAt(1); if(bmd1){ bmd1.dispose(); bmd1 = null; } }}} </code></pre> <p><strong>Particle.as</strong></p> <pre><code>package { import flash.display.MovieClip; import flash.events.Event; import flash.display.Stage; public class Particle extends MovieClip { private var speedX:int; private var speedY:int; private var _s:Stage; public function Particle() { this.graphics.beginFill(0x00CCFF); this.graphics.drawCircle(0,0,Math.random() * 30); speedX = Math.random() * 10 - 5; speedY = Math.random() * 10 - 5; this.addEventListener(Event.ADDED_TO_STAGE, initi); } public function initi(s:Stage):void{ this._s = s; addEventListener(Event.ENTER_FRAME, render); } private function render(e:Event):void{ this.x += Math.random()*speedX; this.y += Math.random()*speedY; if(this.x &gt; _s.stageWidth || this.y &gt; _s.stageHeight || this.x &lt; 0 &amp;&amp; this.y &lt; 0){ this.x = Math.random()*_s.stageWidth; this.y = Math.random()*_s.stageHeight; //removeEventListener(Event.ENTER_FRAME, render); //this.parent.removeChild(this); } } }} </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload