4
votes

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);
            }
        }
    }
}
3
Hah, that's one hell of a question! :) I've heard of such a problems when embedding swf into C++ program. But there's something you should have in mind - as you've properly specified in the title - you are working with images, not with just an objects. Have you tried this with Sprites instead? Anyways, great question, would love to hear some ideas on that! Cheers!Andrey Popov
Grammar-wise, I suppose I was implying that bitmaps are objects. I'll update the post. It actually was Sprites when I first discovered the problem. I asked the question when I first encountered it while developing a pikmin-inspired game. I tore through my code, trying to find out what I did wrong. Convinced I hit a wall, I gave up. Now I've decided that AS3 is too wonderful to leave alone, so I started exploring the project again.Greg Kritzman

3 Answers

1
votes

Im not sure why u add Bitmap's as childs. I think u should Draw all "shapes" on a single BitmapData, using draw(). You can simply draw shapes, and then draw them to BitmapData. I can be more specific if u need more explanation.

0
votes

set bmp.cacheAsBitmap= ture to each Bitmap

0
votes

Aside from drawing to a single BitmapData, an additional method to attempt might be to place your Bitmaps into a single Sprite. Set cacheAsBitmap=true for your Sprite container.