[][分享]实现颜色渐变
一直找不到有关颜色渐变的相关方法,对着源码把绘制过程理了一遍,找到了实现方式,这是代码:
this.canvas = Laya.Render.canvas;
this.context = this.canvas.getContext('2d');
var my_gradient = this.context.createLinearGradient(0,0,0,1136); //创建一个线性渐变
my_gradient.addColorStop(0,"#FF0000");
my_gradient.addColorStop(1,"#0000FF");
let sprite = new Laya.Sprite();
Laya.stage.addChild(sprite);
sprite.graphics.drawRect(0,0,640,1136,my_gradient);
this.canvas = Laya.Render.canvas;
this.context = this.canvas.getContext('2d');
var my_gradient = this.context.createLinearGradient(0,0,0,1136); //创建一个线性渐变
my_gradient.addColorStop(0,"#FF0000");
my_gradient.addColorStop(1,"#0000FF");
let sprite = new Laya.Sprite();
Laya.stage.addChild(sprite);
sprite.graphics.drawRect(0,0,640,1136,my_gradient);
没有找到相关结果
已邀请:
要回复问题请先登录
2 个回复
137*****130
赞同来自: liwenhua
这是效果
liwenhua
赞同来自: