globalAnimate

This commit is contained in:
oc 2019-01-08 23:55:59 +08:00
parent 34e7b520ce
commit 3732f6e493
3 changed files with 53 additions and 77 deletions

View File

@ -48,15 +48,6 @@ control.prototype.setRequestAnimationFrame = function () {
var draw = function(timestamp) { var draw = function(timestamp) {
core.animateFrame.globalTime = core.animateFrame.globalTime||timestamp;
core.animateFrame.boxTime = core.animateFrame.boxTime||timestamp;
core.animateFrame.selectorTime = core.animateFrame.selectorTime||timestamp;
core.animateFrame.animateTime = core.animateFrame.animateTime||timestamp;
core.animateFrame.moveTime = core.animateFrame.moveTime||timestamp;
core.animateFrame.lastLegTime = core.animateFrame.lastLegTime||timestamp;
core.animateFrame.weather.time = core.animateFrame.weather.time||timestamp;
core.saves.autosave.time = core.saves.autosave.time||timestamp;
// move time // move time
if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero) if (core.isPlaying() && core.isset(core.status) && core.isset(core.status.hero)
&& core.isset(core.status.hero.statistics)) { && core.isset(core.status.hero.statistics)) {
@ -66,18 +57,17 @@ control.prototype.setRequestAnimationFrame = function () {
} }
// Global Animate // Global Animate
if (core.animateFrame.globalAnimate && core.isPlaying() && core.isset(core.status.floorId)) { if (timestamp - core.animateFrame.globalTime > core.animateFrame.speed && core.isPlaying()) {
if (timestamp-core.animateFrame.globalTime>core.animateFrame.speed && core.isset(core.status.globalAnimateObjs)) { core.status.globalAnimateStatus++;
for (var a = 0; a < core.status.globalAnimateObjs.length; a++) { if (core.animateFrame.globalAnimate && core.isset(core.status.floorId)) {
var obj = core.status.globalAnimateObjs[a]; // Global Animate
obj.status = (obj.status+1)%(obj.event.animate||1); core.status.globalAnimateObjs.forEach(function (block) {
core.drawBlock(obj, obj.status); core.drawBlock(block, core.status.globalAnimateStatus % (block.event.animate||1));
} });
if ((core.status.autotileAnimateObjs.blocks||[]).length>0) { // Global Autotile Animate
core.status.autotileAnimateObjs.status++;
core.status.autotileAnimateObjs.blocks.forEach(function (block) { core.status.autotileAnimateObjs.blocks.forEach(function (block) {
var cv = core.isset(block.name)?core.canvas[block.name]:core.canvas.event; var cv = core.isset(block.name)?core.canvas[block.name]:core.canvas.event;
cv.clearRect(block.x * 32, block.y * 32, 32, 32); cv.clearRect(block.x * 32, block.y * 32, 32, 32);
@ -85,22 +75,17 @@ control.prototype.setRequestAnimationFrame = function () {
if (block.name == 'bg') { if (block.name == 'bg') {
core.drawImage('bg', core.material.groundCanvas.canvas, block.x * 32, block.y * 32); core.drawImage('bg', core.material.groundCanvas.canvas, block.x * 32, block.y * 32);
} }
core.drawAutotile(cv, core.status.autotileAnimateObjs[block.name+"map"], block, 32, 0, 0, core.status.autotileAnimateObjs.status); core.drawAutotile(cv, core.status.autotileAnimateObjs[block.name+"map"], block, 32, 0, 0, core.status.globalAnimateStatus);
} }
else { else {
core.drawAutotile(cv, core.status.autotileAnimateObjs.map, block, 32, 0, 0, core.status.autotileAnimateObjs.status); core.drawAutotile(cv, core.status.autotileAnimateObjs.map, block, 32, 0, 0, core.status.globalAnimateStatus);
} }
}) });
} }
core.animateFrame.globalTime = timestamp; // Box animate
}
}
// Box
if (timestamp-core.animateFrame.boxTime>core.animateFrame.speed && core.isset(core.status.boxAnimateObjs) && core.status.boxAnimateObjs.length>0) {
core.drawBoxAnimate(); core.drawBoxAnimate();
core.animateFrame.boxTime = timestamp; core.animateFrame.globalTime = timestamp;
} }
// AutosaveTime // AutosaveTime

View File

@ -29,17 +29,16 @@ function core() {
} }
this.animateFrame = { this.animateFrame = {
'globalAnimate': false, 'globalAnimate': false,
'globalTime': null, 'globalTime': 0,
'boxTime': null, 'selectorTime': 0,
'selectorTime': null,
'selectorUp': true, 'selectorUp': true,
'animateTime': null, 'animateTime': 0,
'moveTime': null, 'moveTime': 0,
'lastLegTime': null, 'lastLegTime': 0,
'leftLeg': true, 'leftLeg': true,
'speed': null, 'speed': null,
'weather': { 'weather': {
'time': null, 'time': 0,
'type': null, 'type': null,
'level': 0, 'level': 0,
'nodes': [], 'nodes': [],
@ -98,7 +97,7 @@ function core() {
"ids": {}, "ids": {},
"autosave": { "autosave": {
"data": null, "data": null,
"time": null, "time": 0,
"updated": false, "updated": false,
} }
} }
@ -196,7 +195,8 @@ function core() {
// 动画 // 动画
'globalAnimateObjs': [], 'globalAnimateObjs': [],
'boxAnimateObjs': [], 'boxAnimateObjs': [],
'autotileAnimateObjs': {"status": 0, "blocks": [], "map": null, "bgmap": null, "fgmap": null}, 'autotileAnimateObjs': {"blocks": [], "map": null, "bgmap": null, "fgmap": null},
"globalAnimateStatus": 0,
'animateObjs': [], 'animateObjs': [],
}; };
this.status = {}; this.status = {};
@ -883,6 +883,10 @@ core.prototype.addGlobalAnimate = function (block) {
core.maps.addGlobalAnimate(block); core.maps.addGlobalAnimate(block);
} }
core.prototype.addAutotileGlobalAnimate = function (block) {
core.maps.addAutotileGlobalAnimate(block);
}
////// 删除一个或所有全局动画 ////// ////// 删除一个或所有全局动画 //////
core.prototype.removeGlobalAnimate = function (x, y, all) { core.prototype.removeGlobalAnimate = function (x, y, all) {
core.maps.removeGlobalAnimate(x, y, all); core.maps.removeGlobalAnimate(x, y, all);
@ -893,11 +897,6 @@ core.prototype.setGlobalAnimate = function (speed) {
core.maps.setGlobalAnimate(speed); core.maps.setGlobalAnimate(speed);
} }
////// 同步所有的全局动画效果 //////
core.prototype.syncGlobalAnimate = function () {
core.maps.syncGlobalAnimate();
}
////// 绘制UI层的box动画 ////// ////// 绘制UI层的box动画 //////
core.prototype.drawBoxAnimate = function () { core.prototype.drawBoxAnimate = function () {
core.maps.drawBoxAnimate(); core.maps.drawBoxAnimate();

View File

@ -436,7 +436,7 @@ maps.prototype.drawBgFgMap = function (floorId, canvas, name, animate) {
if (cls == 'autotile') { if (cls == 'autotile') {
core.drawAutotile(canvas, arr, block, 32, 0, 0); core.drawAutotile(canvas, arr, block, 32, 0, 0);
if (animate) if (animate)
core.status.autotileAnimateObjs.blocks.push(core.clone(block)); core.addAutotileGlobalAnimate(block);
} }
else if (cls == 'tileset') { else if (cls == 'tileset') {
var offset = core.icons.getTilesetOffset(id); var offset = core.icons.getTilesetOffset(id);
@ -571,7 +571,7 @@ maps.prototype.drawMap = function (floorId, callback) {
if (core.isset(block.event) && !block.disable) { if (core.isset(block.event) && !block.disable) {
if (block.event.cls == 'autotile') { if (block.event.cls == 'autotile') {
core.drawAutotile(core.canvas.event, mapArray, block, 32, 0, 0); core.drawAutotile(core.canvas.event, mapArray, block, 32, 0, 0);
core.status.autotileAnimateObjs.blocks.push(core.clone(block)); core.addAutotileGlobalAnimate(block);
} }
else { else {
core.drawBlock(block); core.drawBlock(block);
@ -1182,7 +1182,6 @@ maps.prototype.showBlock = function(x, y, floorId) {
if (floorId == core.status.floorId && core.isset(block.event)) { if (floorId == core.status.floorId && core.isset(block.event)) {
core.drawBlock(block); core.drawBlock(block);
core.addGlobalAnimate(block); core.addGlobalAnimate(block);
core.syncGlobalAnimate();
} }
core.updateStatusBar(); core.updateStatusBar();
} }
@ -1304,7 +1303,6 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
if (floorId==core.status.floorId && !block.disable) { if (floorId==core.status.floorId && !block.disable) {
core.drawBlock(block); core.drawBlock(block);
core.addGlobalAnimate(block); core.addGlobalAnimate(block);
core.syncGlobalAnimate();
core.updateStatusBar(); core.updateStatusBar();
} }
} }
@ -1329,11 +1327,16 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
maps.prototype.addGlobalAnimate = function (b) { maps.prototype.addGlobalAnimate = function (b) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return; if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
if (!core.isset(b.event) || !core.isset(b.event.animate) || b.event.animate==1) return; if (!core.isset(b.event) || !core.isset(b.event.animate) || b.event.animate==1) return;
core.status.globalAnimateObjs.push(b);
}
var block = core.clone(b); ////// 添加一个Autotile全局动画 //////
block.status = 0; maps.prototype.addAutotileGlobalAnimate = function (b) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
core.status.globalAnimateObjs.push(block); if (!core.isset(b.event) || b.event.cls!='autotile') return;
var id = b.event.id, img = core.material.images.autotile[id];
if (!core.isset(img) || img.width==96) return;
core.status.autotileAnimateObjs.blocks.push(b);
} }
////// 删除一个或所有全局动画 ////// ////// 删除一个或所有全局动画 //////
@ -1341,8 +1344,9 @@ maps.prototype.removeGlobalAnimate = function (x, y, all, name) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return; if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
if (all) { if (all) {
core.status.globalAnimateStatus = 0;
core.status.globalAnimateObjs = []; core.status.globalAnimateObjs = [];
core.status.autotileAnimateObjs = {"status": 0, "blocks": [], "map": null, "bgmap": null, "fgmap": null}; core.status.autotileAnimateObjs = {"blocks": [], "map": null, "bgmap": null, "fgmap": null};
return; return;
} }
@ -1359,31 +1363,19 @@ maps.prototype.removeGlobalAnimate = function (x, y, all, name) {
////// 设置全局动画的显示效果 ////// ////// 设置全局动画的显示效果 //////
maps.prototype.setGlobalAnimate = function (speed) { maps.prototype.setGlobalAnimate = function (speed) {
if (main.mode=='editor' && main.editor.disableGlobalAnimate) return; if (main.mode=='editor' && main.editor.disableGlobalAnimate) return;
core.syncGlobalAnimate(); core.status.globalAnimateStatus = 0;
core.animateFrame.speed = speed; core.animateFrame.speed = speed;
core.animateFrame.globalAnimate = true; core.animateFrame.globalAnimate = true;
} }
////// 同步所有的全局动画效果 //////
maps.prototype.syncGlobalAnimate = function () {
core.status.globalAnimateObjs.forEach(function (t) {
t.status=0;
})
if (core.isset(core.status.autotileAnimateObjs.status)) {
core.status.autotileAnimateObjs.status = 0;
}
}
////// 绘制UI层的box动画 ////// ////// 绘制UI层的box动画 //////
maps.prototype.drawBoxAnimate = function () { maps.prototype.drawBoxAnimate = function () {
for (var a = 0; a < core.status.boxAnimateObjs.length; a++) { core.status.boxAnimateObjs.forEach(function (obj) {
var obj = core.status.boxAnimateObjs[a];
obj.status = ((obj.status||0)+1)%obj.animate;
core.clearMap('ui', obj.bgx, obj.bgy, obj.bgWidth, obj.bgHeight); core.clearMap('ui', obj.bgx, obj.bgy, obj.bgWidth, obj.bgHeight);
core.fillRect('ui', obj.bgx, obj.bgy, obj.bgWidth, obj.bgHeight, core.material.groundPattern); core.fillRect('ui', obj.bgx, obj.bgy, obj.bgWidth, obj.bgHeight, core.material.groundPattern);
core.drawImage('ui', obj.image, obj.status * 32, obj.pos, core.drawImage('ui', obj.image, core.status.globalAnimateStatus % obj.animate * 32, obj.pos,
32, obj.height, obj.x, obj.y, 32, obj.height); 32, obj.height, obj.x, obj.y, 32, obj.height);
} });
} }
////// 绘制动画的某一帧 ////// ////// 绘制动画的某一帧 //////