AS3 - At exactly 23 empty alpha channels, images below stop drawing
- by user46851
I noticed, while trying to draw large numbers of circles, that occasionally, there would be some kind of visual bug where some circles wouldn't draw properly. Well, I narrowed it down, and have noticed that if there is 23 or more objects with 00 for an alpha value on the same spot, then the objects below don't draw. It appears to be on a pixel-by-pixel basis, since parts of the image still draw.
Originally, this problem was noticed with a class that inherited Sprite. It was confirmed to also be a problem with Sprites, and now Bitmaps, too. If anyone can find a lower-level class than Bitmap which doesn't have this problem, please speak up so we can try to find the origin of the problem.
I prepared a small test class that demonstrates what I mean. You can change the integer value at line 20 in order to see the three tests I came up with to clearly show the problem.
Is there any kind of workaround, or is this just a limit that I have to work with? Has anyone experienced this before? Is it possible I'm doing something wrong, despite the bare-bones implementation?
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.Bitmap;
import flash.display.BitmapData;
public class Main extends Sprite
{
public function Main():void
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
// entry point
Test(3);
}
private function Test(testInt:int):void {
if(testInt==1){
addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000)));
for (var i:int = 0; i < 22; i++) {
addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000)));
}
}
if(testInt==2){
addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000)));
for (var j:int = 0; j < 23; j++) {
addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000)));
}
}
if(testInt==3){
addChild(new Bitmap(new BitmapData(200, 200, true, 0xFFFF0000)));
for (var k:int = 0; k < 22; k++) {
addChild(new Bitmap(new BitmapData(100, 100, true, 0x00000000)));
}
var M:Bitmap = new Bitmap(new BitmapData(100, 100, true, 0x00000000));
M.x += 50;
M.y += 50;
addChild(M);
}
}
}
}