Bitmapdata is cached on html5 target with useCache off

I’m trying to make a loading bar using bitmaps, drawing with copyPixels one over another. But it seems that bitmapdata I use as an empty state is cached and modified even if I turn useCache off. So once it’s drawn with 50% for example it’ll not show less than this amount if I try to redraw it. On Flash taget the bar is showing the right amount but not on html5 target.

       _filledBarPoint = new Point();
		emptyBarSprBitmap = new Bitmap(Assets.getBitmapData("assets/emptBarRect.png", false));
		fullBarSprBitmap = new Bitmap(Assets.getBitmapData("assets/fullBarRect.png", false));
		emptyBarSprBData = Assets.getBitmapData("assets/emptBarRect.png", false);
	
		barWidth = fullBarSprBitmap.width;
		barHeight = fullBarSprBitmap.height;
		barScaleRect = new Rectangle(0, 0, barWidth*0.5, barHeight);//start with 50%
		emptyBarSprBitmap.bitmapData.copyPixels(fullBarSprBitmap.bitmapData, barScaleRect, _filledBarPoint);
		addChild(emptyBarSprBitmap);
       //clean it up
        barScaleRect.setTo(0, 0, emptyBarSprBData.width, emptyBarSprBData.height);
		emptyBarSprBitmap.bitmapData.copyPixels(emptyBarSprBData, barScaleRect, _filledBarPoint);
		barScaleRect.width = barWidth * 0.1;//try to draw 10%
       //draw full bar bitmapData on top again but with 10% of its width - on html5 still shows 50%
		emptyBarSprBitmap.bitmapData.copyPixels(fullBarSprBitmap.bitmapData, barScaleRect, _filledBarPoint);

Thank you for reporting this

With the rewrite of the Asset and AssetLibrary classes, we have many strides to evolve the asset library system, but unfortunately the current architecture makes it hard to cleanly clone() images that have been preloaded (like in HTML5) in order to provide truly unique copies of the same asset, and to avoid duplicating images that are already unique.

I’ve created an issue here:

This is a priority, but may take some time before a mature solution is released.

In the meantime, I recommend that you .clone() the BitmapData received in order to ensure that it is unique

Thank you :slight_smile:

1 Like

I see, well, it’s okay, using .clone() solves it, thank you! :slight_smile:

1 Like