Transparency Issues With threshold() and copyPixels()

  • I've got no idea if this is the HaxeFlixel library that's screwing up, or if it's OpenFL, but functions I've written in ActionScript 3 are not working the same way as they are in my port to Haxe.

    I'm trying to layer two assets on top of each other. I've tried both stamp() and copyPixels() to do so.

    This method works perfectly in ActionScript 3.

    In Avatar.hx:FlxSprite :

    public function new(_username:String) 
        this.pixels = new BitmapData(1722, 68, true, 0x00000000);
        for(itemName in itemArray)
            this.graphic.bitmap.copyPixels(prepareItem(itemName), sheetRect, new Point(0, iy), null, null, true);
    private function prepareItem(assetName:String):BitmapData
        var assetSprite:FlxSprite = new FlxSprite(0, 0, "assets/images/" + assetName + ".png");
        assetSprite.pixels.threshold(assetSprite.pixels, sheetRect, zeroPoint, "==", 0xFF00FF00);
        assetSprite.pixels.threshold(assetSprite.pixels, sheetRect, zeroPoint, "==", 0xFFFF0000);
        return assetSprite.graphic.bitmap;

    When I load the items slightly overlapping each other, parts are erased by each other's overlapping transparencies.

    This is not the case in ActionScript, although there I was adding a final Bitmap object generated from the BitmapData set as the child to the Sprite.

    The two images:
    alt text
    alt text

    Desired outcome:
    alt text

  • My code will work but you have to copy all your pixels to a Bitmap object's bitmapData property. I neglected to implement that part of my Flash project in my OpenFL project.

Log in to reply

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.