vendredi 24 juin 2016

Unity BlendMode

Im pretty new to unity and i had written a simple 2 layer day night system in flash AS3. But im not sure how i could achieve the same thing in unity

This is the AS3 code i was using. It simply adds a black square to the back ground with addNight(). Then addLight() adds a gradient circle to the screen. The effect of light/dark is achieved with

spr.blendMode = BlendMode.LAYER;

and

bound.blendMode = BlendMode.ERASE;

  • Im currently working with c# in unity

    public var spr:Sprite = new Sprite();
    var msk:Sprite = new Sprite();
    
    
    private var gType:String;  
    private var matrix:Matrix;  
    
    private var bound:Sprite;
    
    
    
    public function addNight()
    {
        spr.alpha = .85;
    
        spr.graphics.beginFill(0x000000);
        spr.graphics.drawRect(0,0 ,800,600);
        spr.graphics.endFill();
    
        prnt.addChild(spr);
    
        spr.blendMode = BlendMode.LAYER;
    }
    
    
    
    public function addLight(x:int, y:int)
    {
        var gType:String = GradientType.RADIAL;  
    
        var matrix:Matrix = new Matrix();  
        matrix.createGradientBox(300,300,0,0,0);    
    
        var gColors:Array = [0xFFFFFF, 0x000000];  
        var gAlphas:Array = [.9,0];  
        var gRatio:Array = [0,255];  
    
        var bound:Sprite = new Sprite();  
        bound.graphics.beginGradientFill(gType,gColors,gAlphas,gRatio,matrix);  
        bound.graphics.drawCircle(150,150,150);
        bound.x = bound.y = 0;  
    
        bound.x = x;
        bound.y = y;
        bound.blendMode = BlendMode.ERASE;
        spr.addChild(bound);
    }
    
    

I should also mention, i'm working with Unity2D. Im also willing to use a completely different way of achieving a lighting system

Aucun commentaire:

Enregistrer un commentaire