Bitmapdata relative to entity?


(Mike Evmm) #1

When creating a bitmapdata from inside an entity, it will always position the bitmap data at the entitiy’s position, making anything with a lower x or y than the entity’s not being drawn to the bitmap. How can I fix that? (This sounds confusing explained, so I wrote some code to illustrate:)

    package Entities 
    {
    //imports...
	public class EntityA extends Entity
	{
		
		public function EntityA() 
		{
			var sp1:Sprite = new Sprite();
			sp1.graphics.lineStyle(1, 0xffffff);
			sp1.graphics.lineTo(FP.width, FP.height);
			var bmd1:BitmapData = new BitmapData(10,10);
			bmd1.draw(sp1);
			addGraphic(new Image(bmd1));

			//Draws a line to the right and down from the entities position.


			var sp2:Sprite = new Sprite();
			sp2.graphics.lineStyle(1, 0xffffff);
			sp2.graphics.lineTo(-1,-1);
			sp2.graphics.lineTo(FP.width, FP.height);

			var bmd2:BitmapData(FP.width,FP.height);
			bmd2.draw(sp2);
			addGraphic(new Image(bmd2));

			//Nothing.
		}
	}

    }

P.S.: I know I could use the Draw utils, but sometimes using a bmd would be useful too.


Draw Custom Polygons
(David Williams) #2

Maybe change it to

addGraphic(new Image(bmd1));
...
addGraphic(new Image(bmd2));

(Mike Evmm) #3

Yes, sorry, it’s the second time I got that pointed out. That’s not the issue.


(Zachary Lewis) #4

Since your second sprite starts at (-1, -1) and your bitmap data starts at (0, 0), the operation fails.

Drawing to bmd1.

Drawing to bmd2.


(Mike Evmm) #5

I see, but is there any way I can move my bitmapdata to global (0,0)? (so I can capture the whole stage, even though I’m performing the operation from within an entity)


(Zachary Lewis) #6

You can shift your sprite. If you know your sprite draws to (-10, -14), you can move your sprite (+10, +14), draw it, then shift your bitmap data (-10, -14) to compensate.


(Mike Evmm) #7

Oh, so there is no way to actually move the bitmapdata’s actual “coordinates” then? Oh well, thanks for your help.


(Zachary Lewis) #8

You can pass in a transform matrix to the bmd2.draw to offset the drawn image if it’s easier.

BitmapData.draw()