Merge remote-tracking branch 'refs/remotes/origin/plugins' into refactoring-editor
This commit is contained in:
commit
a87e62ba26
@ -8,6 +8,7 @@ editor_file = function (editor, callback) {
|
|||||||
'data.comment': 'dataComment',
|
'data.comment': 'dataComment',
|
||||||
'functions.comment': 'functionsComment',
|
'functions.comment': 'functionsComment',
|
||||||
'events.comment': 'eventsComment',
|
'events.comment': 'eventsComment',
|
||||||
|
'plugins.comment': 'pluginsComment',
|
||||||
}
|
}
|
||||||
for (var key in commentjs) {
|
for (var key in commentjs) {
|
||||||
(function (key) {
|
(function (key) {
|
||||||
@ -849,6 +850,65 @@ editor_file = function (editor, callback) {
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
var plmap = {};
|
||||||
|
var pljson = JSON.stringify(plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1, function (k, v) {
|
||||||
|
if (v instanceof Function) {
|
||||||
|
var id_ = editor.guid();
|
||||||
|
plmap[id_] = v.toString();
|
||||||
|
return id_;
|
||||||
|
} else if(v===null){
|
||||||
|
var id_ = editor.guid();
|
||||||
|
plmap[id_] = 'null';
|
||||||
|
return id_;
|
||||||
|
} return v
|
||||||
|
}, 4);
|
||||||
|
var plobj = JSON.parse(pljson);
|
||||||
|
editor_file.pluginsMap = plmap;
|
||||||
|
editor_file.pluginsObj = plobj;
|
||||||
|
var buildpllocobj = function (locObj) {
|
||||||
|
for (var key in locObj) {
|
||||||
|
if (typeof(locObj[key]) !== typeof('')) buildpllocobj(locObj[key]);
|
||||||
|
else locObj[key] = plmap[locObj[key]];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
editor_file.editPlugins = function (actionList, callback) {
|
||||||
|
/*actionList:[
|
||||||
|
["change","['test']","function(x,y){console.log(x,y)}"],
|
||||||
|
]
|
||||||
|
为[]时只查询不修改
|
||||||
|
*/
|
||||||
|
if (!isset(callback)) {
|
||||||
|
printe('未设置callback');
|
||||||
|
throw('未设置callback')
|
||||||
|
}
|
||||||
|
;
|
||||||
|
if (isset(actionList) && actionList.length > 0) {
|
||||||
|
saveSetting('plugins', actionList, function (err) {
|
||||||
|
callback([
|
||||||
|
(function () {
|
||||||
|
var locObj = JSON.parse(JSON.stringify(plobj));
|
||||||
|
buildpllocobj(locObj);
|
||||||
|
return locObj;
|
||||||
|
})(),
|
||||||
|
editor_file.pluginsComment,
|
||||||
|
err]);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
callback([
|
||||||
|
(function () {
|
||||||
|
var locObj = JSON.parse(JSON.stringify(plobj));
|
||||||
|
buildpllocobj(locObj);
|
||||||
|
return locObj;
|
||||||
|
})(),
|
||||||
|
editor_file.pluginsComment,
|
||||||
|
null]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//callback([obj,commentObj,err:String])
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var isset = function (val) {
|
var isset = function (val) {
|
||||||
if (val == undefined || val == null) {
|
if (val == undefined || val == null) {
|
||||||
return false;
|
return false;
|
||||||
@ -1025,6 +1085,25 @@ editor_file = function (editor, callback) {
|
|||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (file == 'plugins') {
|
||||||
|
actionList.forEach(function (value) {
|
||||||
|
if(value[0]==='add'){
|
||||||
|
eval("plobj" + value[1] + '=' + JSON.stringify(value[2]));
|
||||||
|
} else {
|
||||||
|
eval("plmap[plobj" + value[1] + ']=' + JSON.stringify(value[2]));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
var plraw = JSON.stringify(plobj,null,4);
|
||||||
|
for (var id_ in plmap) {
|
||||||
|
plraw = plraw.replace('"' + id_ + '"', plmap[id_])
|
||||||
|
}
|
||||||
|
var datastr = 'var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = \n';
|
||||||
|
datastr += plraw;
|
||||||
|
fs.writeFile('project/plugins.js', encode(datastr), 'base64', function (err, data) {
|
||||||
|
callback(err);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
callback('出错了,要设置的文件名不识别');
|
callback('出错了,要设置的文件名不识别');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -13,6 +13,7 @@ editor_mode = function (editor) {
|
|||||||
'appendpic': 'left1',
|
'appendpic': 'left1',
|
||||||
|
|
||||||
'commonevent': 'left9',
|
'commonevent': 'left9',
|
||||||
|
'plugins': 'left10',
|
||||||
}
|
}
|
||||||
this._ids = {}
|
this._ids = {}
|
||||||
this.dom = {}
|
this.dom = {}
|
||||||
@ -385,6 +386,9 @@ editor_mode = function (editor) {
|
|||||||
case 'commonevent':
|
case 'commonevent':
|
||||||
editor.file.editCommonEvent(actionList, cb);
|
editor.file.editCommonEvent(actionList, cb);
|
||||||
break;
|
break;
|
||||||
|
case 'plugins':
|
||||||
|
editor.file.editPlugins(actionList, cb);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -394,7 +398,7 @@ editor_mode = function (editor) {
|
|||||||
if (editor_mode.mode != mode) {
|
if (editor_mode.mode != mode) {
|
||||||
if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList);
|
if (mode === 'save') editor_mode.doActionList(editor_mode.mode, editor_mode.actionList);
|
||||||
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
|
if (editor_mode.mode === 'nextChange' && mode) editor_mode.showMode(mode);
|
||||||
editor_mode.mode = mode;
|
if (mode !== 'save') editor_mode.mode = mode;
|
||||||
editor_mode.actionList = [];
|
editor_mode.actionList = [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -526,6 +530,19 @@ editor_mode = function (editor) {
|
|||||||
tableinfo.listen(tableinfo.guids);
|
tableinfo.listen(tableinfo.guids);
|
||||||
if (Boolean(callback)) callback();
|
if (Boolean(callback)) callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
editor_mode.prototype.plugins = function (callback) {
|
||||||
|
var objs = [];
|
||||||
|
editor.file.editPlugins([], function (objs_) {
|
||||||
|
objs = objs_;
|
||||||
|
//console.log(objs_)
|
||||||
|
});
|
||||||
|
//只查询不修改时,内部实现不是异步的,所以可以这么写
|
||||||
|
var tableinfo = editor_mode.objToTable_(objs[0], objs[1]);
|
||||||
|
document.getElementById('table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6').innerHTML = tableinfo.HTML;
|
||||||
|
tableinfo.listen(tableinfo.guids);
|
||||||
|
if (Boolean(callback)) callback();
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
27
_server/plugins.comment.js
Normal file
27
_server/plugins.comment.js
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
var plugins_comment_c456ea59_6018_45ef_8bcc_211a24c627dc =
|
||||||
|
{
|
||||||
|
"_type": "object",
|
||||||
|
"_data": function (key) {
|
||||||
|
var obj = {
|
||||||
|
"test": {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "typeof(thiseval)=='string'",
|
||||||
|
"_data": "插件函数执行测试, 这个函数在导入后被直接执行(因此不允许删除)"
|
||||||
|
},
|
||||||
|
"drawLight": {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "typeof(thiseval)=='string' || thiseval==null",
|
||||||
|
"_data": "绘制灯光/漆黑层效果"
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if (obj[key]) return obj[key];
|
||||||
|
return {
|
||||||
|
"_leaf": true,
|
||||||
|
"_type": "textarea",
|
||||||
|
"_range": "typeof(thiseval)=='string' || thiseval==null",
|
||||||
|
"_data": "自定义插件"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -259,6 +259,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="left10" class='leftTab' style="z-index:-1;opacity: 0;"><!-- plugins -->
|
||||||
|
<h3 class="leftTabHeader">插件编写 <button onclick="editor.mode.onmode('save')">保存</button> <button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button> <button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
|
||||||
|
</h3>
|
||||||
|
<div class="leftTabContent">
|
||||||
|
<div class='etable'>
|
||||||
|
<table>
|
||||||
|
<tbody id='table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6'>
|
||||||
|
<tr>
|
||||||
|
<td>条目</td>
|
||||||
|
<td>注释</td>
|
||||||
|
<td>值</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="mid">
|
<div id="mid">
|
||||||
<div class="col" id='mapColMark'></div>
|
<div class="col" id='mapColMark'></div>
|
||||||
<div class="row" id='mapRowMark'></div>
|
<div class="row" id='mapRowMark'></div>
|
||||||
@ -323,6 +340,7 @@
|
|||||||
<option value="functions">脚本编辑</option>
|
<option value="functions">脚本编辑</option>
|
||||||
<option value="appendpic">追加素材</option>
|
<option value="appendpic">追加素材</option>
|
||||||
<option value="commonevent">公共事件</option>
|
<option value="commonevent">公共事件</option>
|
||||||
|
<option value="plugins">插件编写</option>
|
||||||
</select>
|
</select>
|
||||||
<select id="brushMod" style="clear:right">
|
<select id="brushMod" style="clear:right">
|
||||||
<option value="line">画线</option>
|
<option value="line">画线</option>
|
||||||
|
|||||||
18
editor.html
18
editor.html
@ -255,6 +255,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="left10" class='leftTab' style="z-index:-1;opacity: 0;"><!-- plugins -->
|
||||||
|
<h3 class="leftTabHeader">插件编写 <button onclick="editor.mode.onmode('save')">保存</button> <button onclick="editor.mode.changeDoubleClickModeByButton('add')">添加</button> <button onclick="editor.mode.changeDoubleClickModeByButton('delete')">删除</button>
|
||||||
|
</h3>
|
||||||
|
<div class="leftTabContent">
|
||||||
|
<div class='etable'>
|
||||||
|
<table>
|
||||||
|
<tbody id='table_e2c034ec_47c6_48ae_8db8_4f8f32fea2d6'>
|
||||||
|
<tr>
|
||||||
|
<td>条目</td>
|
||||||
|
<td>注释</td>
|
||||||
|
<td>值</td>
|
||||||
|
</tr>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div id="mid">
|
<div id="mid">
|
||||||
<table class="col" id='mapColMark'></table>
|
<table class="col" id='mapColMark'></table>
|
||||||
<table class="row" id='mapRowMark'></table>
|
<table class="row" id='mapRowMark'></table>
|
||||||
@ -290,6 +307,7 @@
|
|||||||
<option value="functions">脚本编辑</option>
|
<option value="functions">脚本编辑</option>
|
||||||
<option value="appendpic">追加素材</option>
|
<option value="appendpic">追加素材</option>
|
||||||
<option value="commonevent">公共事件</option>
|
<option value="commonevent">公共事件</option>
|
||||||
|
<option value="plugins">插件编写</option>
|
||||||
</select>
|
</select>
|
||||||
<br/>
|
<br/>
|
||||||
<span style="font-size: 12px;">
|
<span style="font-size: 12px;">
|
||||||
|
|||||||
2
main.js
2
main.js
@ -81,7 +81,7 @@ function main() {
|
|||||||
'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core'
|
'loader', 'control', 'utils', 'items', 'icons', 'maps', 'enemys', 'events', 'actions', 'data', 'ui', 'core'
|
||||||
];
|
];
|
||||||
this.pureData = [
|
this.pureData = [
|
||||||
'data', 'enemys', 'icons', 'maps', 'items', 'functions', 'events'
|
'data', 'enemys', 'icons', 'maps', 'items', 'functions', 'events', 'plugins'
|
||||||
];
|
];
|
||||||
this.materials = [
|
this.materials = [
|
||||||
'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48'
|
'animates', 'enemys', 'hero', 'items', 'npcs', 'terrains', 'enemy48', 'npc48'
|
||||||
|
|||||||
@ -1422,78 +1422,22 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
|
|||||||
|
|
||||||
},
|
},
|
||||||
"plugin": function () {
|
"plugin": function () {
|
||||||
////// 插件编写,可以在这里写自己额外需要执行的脚本 //////
|
////// 插件编写,此处会导入插件编写中的所有函数 //////
|
||||||
|
|
||||||
// 在这里写的代码,在所有模块加载完毕后,游戏开始前会被执行
|
// 在这里写的代码,在所有模块加载完毕后,游戏开始前会被执行
|
||||||
console.log("插件编写测试");
|
console.log("插件编写测试");
|
||||||
// 可以写一些其他的被直接执行的代码
|
// 可以写一些其他的被直接执行的代码
|
||||||
|
|
||||||
// 在这里写所有需要自定义的函数
|
var pluginsData=plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1
|
||||||
// 写法必须是 this.xxx = function (args) { ...
|
for(var functionName in pluginsData){
|
||||||
// 如果不写this的话,函数将无法被外部所访问
|
this[functionName]=pluginsData[functionName]
|
||||||
this.test = function () {
|
|
||||||
console.log("插件函数执行测试");
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
|
|
||||||
// 【参数说明】
|
|
||||||
// name:必填,要绘制到的画布名;可以是一个系统画布,或者是个自定义画布;如果不存在则创建
|
|
||||||
// color:可选,只能是一个0~1之间的数,为不透明度的值。不填则默认为0.9。
|
|
||||||
// lights:可选,一个数组,定义了每个独立的灯光。
|
|
||||||
// 其中每一项是三元组 [x,y,r] x和y分别为该灯光的横纵坐标,r为该灯光的半径。
|
|
||||||
// lightDec:可选,0到1之间,光从多少百分比才开始衰减(在此范围内保持全亮),不设置默认为0。
|
|
||||||
// 比如lightDec为0.5代表,每个灯光部分内圈50%的范围全亮,50%以后才开始快速衰减。
|
|
||||||
// 【调用样例】
|
|
||||||
// core.plugin.drawLight('curtain'); // 在curtain层绘制全图不透明度0.9,等价于更改画面色调为[0,0,0,0.9]。
|
|
||||||
// core.plugin.drawLight('ui', 0.95, [[25,11,46]]); // 在ui层绘制全图不透明度0.95,其中在(25,11)点存在一个半径为46的灯光效果。
|
|
||||||
// core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层,不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果,灯光中心不透明度0.1。
|
|
||||||
// core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层,且存在三个灯光效果,分别是中心(25,11)半径46,中心(105,121)半径88,中心(301,221)半径106。
|
|
||||||
// core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果,它们在内圈40%范围内保持全亮,且40%后才开始衰减。
|
|
||||||
this.drawLight = function (name, color, lights, lightDec) {
|
|
||||||
// 清空色调层;也可以修改成其它层比如animate/weather层,或者用自己创建的canvas
|
|
||||||
var ctx = core.getContextByName(name);
|
|
||||||
if (ctx == null) {
|
|
||||||
if (typeof name == 'string')
|
|
||||||
ctx = core.createCanvas(name, 0, 0, core.__PIXELS__, core.__PIXELS__, 98);
|
|
||||||
else return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx.mozImageSmoothingEnabled = false;
|
|
||||||
ctx.webkitImageSmoothingEnabled = false;
|
|
||||||
ctx.msImageSmoothingEnabled = false;
|
|
||||||
ctx.imageSmoothingEnabled = false;
|
|
||||||
|
|
||||||
core.clearMap(name);
|
|
||||||
// 绘制色调层,默认不透明度
|
|
||||||
if (color == null) color = 0.9;
|
|
||||||
ctx.fillStyle = "rgba(0,0,0,"+color+")";
|
|
||||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
|
||||||
|
|
||||||
lightDec = core.clamp(lightDec, 0, 1);
|
|
||||||
|
|
||||||
// 绘制每个灯光效果
|
|
||||||
ctx.globalCompositeOperation = 'destination-out';
|
|
||||||
lights.forEach(function (light) {
|
|
||||||
// 坐标,半径,中心不透明度
|
|
||||||
var x = light[0], y = light[1], r = light[2];
|
|
||||||
// 计算衰减距离
|
|
||||||
var decDistance = parseInt(r * lightDec);
|
|
||||||
// 正方形区域的直径和左上角坐标
|
|
||||||
var grd=ctx.createRadialGradient(x,y,decDistance,x,y,r);
|
|
||||||
grd.addColorStop(0, "rgba(0,0,0,1)");
|
|
||||||
grd.addColorStop(1, "rgba(0,0,0,0)");
|
|
||||||
ctx.beginPath();
|
|
||||||
ctx.fillStyle=grd;
|
|
||||||
ctx.arc(x,y,r,0,2*Math.PI);
|
|
||||||
ctx.fill();
|
|
||||||
});
|
|
||||||
ctx.globalCompositeOperation = 'source-over';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
||||||
|
|
||||||
|
// 可以在此处直接执行插件编写中的函数
|
||||||
|
core.plugin.test();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
62
project/plugins.js
Normal file
62
project/plugins.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
||||||
|
{
|
||||||
|
"test": function(){
|
||||||
|
console.log("插件函数执行测试");
|
||||||
|
},
|
||||||
|
"drawLight": function (name, color, lights, lightDec) {
|
||||||
|
// 绘制灯光/漆黑层效果。调用方式 core.plugin.drawLight(...)
|
||||||
|
// 【参数说明】
|
||||||
|
// name:必填,要绘制到的画布名;可以是一个系统画布,或者是个自定义画布;如果不存在则创建
|
||||||
|
// color:可选,只能是一个0~1之间的数,为不透明度的值。不填则默认为0.9。
|
||||||
|
// lights:可选,一个数组,定义了每个独立的灯光。
|
||||||
|
// 其中每一项是三元组 [x,y,r] x和y分别为该灯光的横纵坐标,r为该灯光的半径。
|
||||||
|
// lightDec:可选,0到1之间,光从多少百分比才开始衰减(在此范围内保持全亮),不设置默认为0。
|
||||||
|
// 比如lightDec为0.5代表,每个灯光部分内圈50%的范围全亮,50%以后才开始快速衰减。
|
||||||
|
// 【调用样例】
|
||||||
|
// core.plugin.drawLight('curtain'); // 在curtain层绘制全图不透明度0.9,等价于更改画面色调为[0,0,0,0.9]。
|
||||||
|
// core.plugin.drawLight('ui', 0.95, [[25,11,46]]); // 在ui层绘制全图不透明度0.95,其中在(25,11)点存在一个半径为46的灯光效果。
|
||||||
|
// core.plugin.drawLight('test', 0.2, [[25,11,46,0.1]]); // 创建一个test图层,不透明度0.2,其中在(25,11)点存在一个半径为46的灯光效果,灯光中心不透明度0.1。
|
||||||
|
// core.plugin.drawLight('test2', 0.9, [[25,11,46],[105,121,88],[301,221,106]]); // 创建test2图层,且存在三个灯光效果,分别是中心(25,11)半径46,中心(105,121)半径88,中心(301,221)半径106。
|
||||||
|
// core.plugin.drawLight('xxx', 0.3, [[25,11,46],[105,121,88,0.2]], 0.4); // 存在两个灯光效果,它们在内圈40%范围内保持全亮,且40%后才开始衰减。
|
||||||
|
|
||||||
|
// 清空色调层;也可以修改成其它层比如animate/weather层,或者用自己创建的canvas
|
||||||
|
var ctx = core.getContextByName(name);
|
||||||
|
if (ctx == null) {
|
||||||
|
if (typeof name == 'string')
|
||||||
|
ctx = core.createCanvas(name, 0, 0, core.__PIXELS__, core.__PIXELS__, 98);
|
||||||
|
else return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.mozImageSmoothingEnabled = false;
|
||||||
|
ctx.webkitImageSmoothingEnabled = false;
|
||||||
|
ctx.msImageSmoothingEnabled = false;
|
||||||
|
ctx.imageSmoothingEnabled = false;
|
||||||
|
|
||||||
|
core.clearMap(name);
|
||||||
|
// 绘制色调层,默认不透明度
|
||||||
|
if (color == null) color = 0.9;
|
||||||
|
ctx.fillStyle = "rgba(0,0,0,"+color+")";
|
||||||
|
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||||
|
|
||||||
|
lightDec = core.clamp(lightDec, 0, 1);
|
||||||
|
|
||||||
|
// 绘制每个灯光效果
|
||||||
|
ctx.globalCompositeOperation = 'destination-out';
|
||||||
|
lights.forEach(function (light) {
|
||||||
|
// 坐标,半径,中心不透明度
|
||||||
|
var x = light[0], y = light[1], r = light[2];
|
||||||
|
// 计算衰减距离
|
||||||
|
var decDistance = parseInt(r * lightDec);
|
||||||
|
// 正方形区域的直径和左上角坐标
|
||||||
|
var grd=ctx.createRadialGradient(x,y,decDistance,x,y,r);
|
||||||
|
grd.addColorStop(0, "rgba(0,0,0,1)");
|
||||||
|
grd.addColorStop(1, "rgba(0,0,0,0)");
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.fillStyle=grd;
|
||||||
|
ctx.arc(x,y,r,0,2*Math.PI);
|
||||||
|
ctx.fill();
|
||||||
|
});
|
||||||
|
ctx.globalCompositeOperation = 'source-over';
|
||||||
|
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user