Can’t seem to work this one out.
I’m using the flash API to draw out a gradient fill. It works fine on neko but gives a type error in flash.
source/Graphics.hx:30: characters 57-65 : Array should be Array
source/Graphics.hx:30: characters 57-65 : Type parameters are invariant
source/Graphics.hx:30: characters 57-65 : Int should be UInt
source/Graphics.hx:30: characters 57-65 : For function argument ‘colors’
var sprite = new FlxSprite().makeGraphic(width,height,0);
var _colours = [0x13A5CA, 0x0D6C82];
var _alphas = [1, 1];
var _ratios = [0, 255];
var _matrix = new Matrix();
var _holeRadius = width;
var _holeX = width/2;
var _holeY = height/2;
_matrix.createGradientBox(_holeRadius, _holeRadius/2, 0, _holeX - _holeRadius/2, _holeY - _holeRadius/4);
var _shape = new openfl.display.Shape();
_shape.graphics.clear();
_shape.graphics.beginGradientFill(GradientType.RADIAL, _colours, _alphas, _ratios, _matrix);
_shape.graphics.drawRect(0,0,width,height);
_shape.graphics.endFill();
sprite.pixels.draw(_shape);
I understand that flash uses unsigned integers … But in this case I’m just defining _colors as a standard array - Do I need to do an #if flash for this ? Is there no other (cleaner) way to do it ?
Looking at openfl/display/Graphics.hx beginGradientFill it defines colors as Array<Dynamic> - why is the compiler complaining ?
Thanks for reading.