Hello, Away3D Team!
Last day I tried to implement simple smoke-like effect based on the Sprite3D class.
smokePuff.as
package
{
import flash.events.Event;
import flash.geom.Vector3D;
import away3d.containers.View3D;
import away3d.entities.Sprite3D;
import away3d.materials.BitmapMaterial;
public class smokePuff extends Sprite3D
{
[Embed(source="/../embed/puff.png")]
private var _texture:Class;
private var _sc:Number = 1.3;
private var _view:View3D;
private var _mtl:BitmapMaterial;
public function smokePuff(view:View3D, pos:Vector3D) {
_view = view;
_mtl = new BitmapMaterial(new flake_texture().bitmapData, true, false, false);
_mtl.alphaBlending = true;
super(_mtl, 16 + 16 * Math.random(), 16 + 16 * Math.random());
_mtl.alpha = 1;
this.position = pos;
_view.scene.addChild(this);
_view.addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
}
private function loop(e:Event):void {
this.scale(_sc);
if (_mtl.alpha < 0){
remove();
} else {
_mtl.alpha -= .1;
}
}
private function remove():void {
_view.removeEventListener(Event.ENTER_FRAME, loop);
_view.scene.removeChild(this);
// should I do this???
this.dispose(true);
_mtl.dispose(true);
}
}
}
Then in main class I call smokePuff each frame as follows:
...
for (var i:int = 0; i < 4; i++){
var sm:smokePuff = new smokePuff(_view, SMOKE_INIT_POS.add(new Vector3D(25 - 50 * Math.random(), -250 - 50 * Math.random(), 25 - 50 * Math.random())));
}
...
where SMOKE_INIT_POS is smokes’ initial position
For first 5 seconds it works fine, but then… it dramatically slows down! It seems, that no one of just created smokePuffs removed from both view3D and PC’s memory. The question is WHY , coz I used to remove it (remove():void).
Please, help to solve my problem and sorry for bad english…