I get the following:
ArgumentError: Error #2015: Invalid BitmapData.
at flash.display::BitmapData$iinit()
at com.psyphon.pcl.display::BitMapRenderer$iinit()[C:\Users\Dylan\Desktop\POC\com\psyphon\pcl\display\BitMapRenderer.as:40]
at com.psyphon.poc::Main$iinit()[C:\Users\Dylan\Desktop\POC\com\psyphon\poc\Main.as:46]
Whenever I initialize the following class using:
renderer = new BitMapRenderer(stage.width, stage.height);
And it does not matter what stagesize i set so it isnt a bitmapdata size/memory issue (AFAIK)…
package com.psyphon.pcl.display {
//Flash libs
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.text.*;
import flash.ui.*;
import flash.utils.*;
//Extra libs
import com.psyphon.pcl.*;
import com.psyphon.pcl.math.*;
import com.psyphon.pcl.display.*;
import com.psyphon.poc.*;
import de.polygonal.ds.*;
public class BitMapRenderer extends Sprite
{
public static const DEFAULT_COLOR:uint = 0x00000000;
protected var drawCanvas: BitmapData;
protected var bufferCanvas: BitmapData;
protected var bitmap: Bitmap;
protected var currentCanvas: BitmapData;
private var renderStack: ArrayedQueue;
public function BitMapRenderer( width:Number = 512, height:Number = 512)
{
renderStack = new ArrayedQueue(9); //suppports 512 objects (2^9), if you need more change the value to 10 for 1024 entities
drawCanvas = new BitmapData(width, height, false, DEFAULT_COLOR);
bitmap = addChild( new Bitmap(drawCanvas)) as Bitmap;
}
public function addEntity(ent:Entity) : void
{
renderStack.enqueue(ent);
}
public function draw() : void
{
drawCanvas.copyPixels(bufferCanvas, bufferCanvas.rect, new Point(0,0));
currentCanvas = drawCanvas;
}
public function buffer() : void
{
currentCanvas = bufferCanvas = new BitmapData( width, height, false, DEFAULT_COLOR );
var i:Iterator = renderStack.getIterator()
while (i.hasNext())
{
var ent:Entity = i.next();
renderItem(ent);
}
draw();
}
public function renderItem(ent:Entity) : void
{
if(ent.texture.loaded){
//ent.mat.identity();
//ent.mat.translate(-texture.bitmap.width/2, -texture.bitmap.height/2);
//ent.mat.rotate(Math.atan2(vector.y, vector.x));
//ent.mat.translate(pos.x, pos.y);
ent.colorTransform.alphaMultiplier = 100;
currentCanvas.copyPixels(ent.texture.bitmap,ent.texture.bitmap.rect,new Point(ent.pos.x,ent.pos.y),null,null,true)
//r.draw(texture.bitmap, mat, colorTransform);
}
}
}
}