drawHeroAnimate

This commit is contained in:
ckcz123 2019-12-26 16:18:42 +08:00
parent 8ba9abc331
commit 88078448a7
5 changed files with 56 additions and 13 deletions

View File

@ -1624,6 +1624,12 @@ core.drawAnimate(name, x, y, callback)
此函数会返回一个动画id可以通过core.stopAnimate()立刻停止该动画的播放。
core.drawHeroAnimate(name, callback)
绘制一个跟随勇士行动的动画。name为动画名callback为绘制完毕的回调函数。
此函数将播放动画音效,并异步开始绘制该动画。
此函数会返回一个动画id可以通过core.stopAnimate()立刻停止该动画的播放。
core.stopAnimate(id, doCallback)
立刻停止某个动画的播放。id为上面core.drawAnimate的返回值。
如果doCallback为真则会执行该动画所对应的回调函数。

View File

@ -169,7 +169,17 @@ control.prototype._animationFrame_animate = function (timestamp) {
return obj.index < obj.animate.frames.length;
});
core.status.animateObjs.forEach(function (obj) {
core.maps._drawAnimateFrame(obj.animate, obj.centerX, obj.centerY, obj.index++);
if (obj.hero) {
// calculate position
var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction');
var offset = 4 * core.status.heroMoving;
if (offset < 0) offset = 0;
var way = core.utils.scan[direction];
var centerX = 32 * x + way.x * offset + 16, centerY = 32 * y + way.y * offset + 16;
core.maps._drawAnimateFrame(obj.animate, centerX, centerY, obj.index++);
} else {
core.maps._drawAnimateFrame(obj.animate, obj.centerX, obj.centerY, obj.index++);
}
});
core.animateFrame.animateTime = timestamp;
}
@ -996,7 +1006,7 @@ control.prototype.checkBlock = function () {
if (damage) {
core.status.hero.hp -= damage;
core.drawTip("受到"+(core.status.checkBlock.type[loc]||"伤害")+damage+"点");
core.drawAnimate("zone", x, y);
core.drawHeroAnimate("zone");
this._checkBlock_disableQuickShop();
core.status.hero.statistics.extraDamage += damage;
if (core.status.hero.hp <= 0) {

View File

@ -1304,9 +1304,12 @@ events.prototype._action_unfollow = function (data, x, y, prefix) {
}
events.prototype._action_animate = function (data, x, y, prefix) {
if (data.loc == 'hero') data.loc = [core.getHeroLoc('x'), core.getHeroLoc('y')];
else data.loc = this.__action_getLoc(data.loc, x, y, prefix);
this.__action_doAsyncFunc(data.async, core.drawAnimate, data.name, data.loc[0], data.loc[1]);
if (data.loc == 'hero') {
this.__action_doAsyncFunc(data.async, core.drawHeroAnimate, data.name);
} else {
data.loc = this.__action_getLoc(data.loc, x, y, prefix);
this.__action_doAsyncFunc(data.async, core.drawAnimate, data.name, data.loc[0], data.loc[1]);
}
}
events.prototype._action_setViewport = function (data, x, y, prefix) {

View File

@ -2030,13 +2030,7 @@ maps.prototype.drawAnimate = function (name, x, y, callback) {
name = core.getMappedName(name);
// 正在播放录像:不显示动画
if (core.isReplaying()) {
if (callback) callback();
return -1;
}
// 检测动画是否存在
if (!core.material.animates[name] || x == null || y == null) {
if (core.isReplaying() || !core.material.animates[name] || x == null || y == null) {
if (callback) callback();
return -1;
}
@ -2059,6 +2053,33 @@ maps.prototype.drawAnimate = function (name, x, y, callback) {
return id;
}
////// 绘制一个跟随勇士的动画 //////
maps.prototype.drawHeroAnimate = function (name, callback) {
name = core.getMappedName(name);
// 正在播放录像或动画不存在:不显示动画
if (core.isReplaying() || !core.material.animates[name]) {
if (callback) callback();
return -1;
}
// 开始绘制
var animate = core.material.animates[name];
// 播放音效
core.playSound(animate.se);
var id = setTimeout(null);
core.status.animateObjs.push({
"id": id,
"animate": animate,
"hero": true,
"index": 0,
"callback": callback
});
return id;
}
////// 绘制动画的某一帧 //////
maps.prototype._drawAnimateFrame = function (animate, centerX, centerY, index) {
var frame = animate.frames[index];

View File

@ -266,7 +266,10 @@ var functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a =
if (!(core.material.animates[equipAnimate] || {}).se)
core.playSound('attack.mp3');
// 强制战斗的战斗动画
core.drawAnimate(equipAnimate, x != null ? x : core.getHeroLoc('x'), y != null ? y : core.getHeroLoc('y'));
if (x != null && y != null)
core.drawAnimate(equipAnimate, x, y);
else
core.drawHeroAnimate(equipAnimate);
var damage = core.enemys.getDamage(enemyId, x, y);
if (damage == null) damage = core.status.hero.hp + 1;