Total Posts: 5
Joined: December 05, 2011
|
I've found inconsistent behavior between Flash and Windows targets when using draw() with a matrix, when the target point is in the negative x axis.
Here's a comparison between the two targets:

And here's the code that produces it:
var source = new BitmapData(200, 50, false, 0x000000);
var target = new BitmapData(200, 200, false, 0x999999);
target.draw(source); // draw an instance at x=0
var m = new Matrix();
m.translate(50, 60);
target.draw(source, m); // draw an instance at x=50
m = new Matrix();
m.translate(-50, 120);
target.draw(source, m); // draw an instance at x=-50 - fails on Windows target
var b = new Bitmap(target);
b.x = 100;
b.y = 20;
Lib.current.addChild(b);
As you can see, Flash does the expected behavior - always drawing the visible area of the black box. Windows (and other cpp targets I expect) fail to draw the 3rd block, which is placed 'off-screen'.
I did a quick test and this problem doesn't seem to occur when the image is in the negative y axis.
This has consequences when for instance trying to use draw() with animated spritesheets with transparency, so I'm having to do some workarounds right now.
Tags:
Posted on December 14, 2011 at 8:53 AM
|
Total Posts: 2
Joined: January 05, 2012
|
Re: IBitmapDrawable.draw inconsistency - Flash vs. Windows
Thanks fritzu, saved me the trouble of posting the same issue!
Yes, negative Matrix translations appear to invalidate the requested draw / nme_render_surface_to_surface.
My test mock was:
var l_redSquare:BitmapData = new BitmapData( 20, 20, false, 0xFF0000 );
var l_canvas:BitmapData = new BitmapData( 100, 100, true, 0x00 );
var l_matrix:Matrix = new Matrix();
l_matrix.tx = -10;
l_canvas.draw( l_redSquare, l_matrix );
Lib.current.addChild( new Bitmap( l_canvas ) );
// I expect a 10x20 red square, I get nothing.
I use negative values as often as positive values. I'm considering mad workarounds like flipping the associated bitmapDatas & matrix horizontally and vertically, applying the result then flipping back? Fritzu, have you developed any generic workaround?
Posted on January 05, 2012 at 2:06 PM
|
Total Posts: 5
Joined: December 05, 2011
|
Re: IBitmapDrawable.draw inconsistency - Flash vs. Windows
Didn't spend much time on a workaround I'm afraid. In my case I just needed the colorTransform capabilities of draw() rather than geometry so I'm doing it in two steps with copyPixels() instead.
Pretty nasty bug though - took me a while to track down what was going on...
Posted on January 06, 2012 at 7:23 AM
|