锁定视角
This commit is contained in:
parent
87f2d7e886
commit
037189adc5
@ -202,12 +202,7 @@ control.prototype._animationFrame_heroMoving = function (timestamp) {
|
|||||||
core.animateFrame.leftLeg = !core.animateFrame.leftLeg;
|
core.animateFrame.leftLeg = !core.animateFrame.leftLeg;
|
||||||
core.animateFrame.moveTime = timestamp;
|
core.animateFrame.moveTime = timestamp;
|
||||||
}
|
}
|
||||||
var way = core.utils.scan2[core.getHeroLoc('direction')],
|
core.drawHero(core.animateFrame.leftLeg ? 'leftFoot' : 'rightFoot', 4 * core.status.heroMoving);
|
||||||
heroMoving = core.status.heroMoving;
|
|
||||||
core.drawHero(core.animateFrame.leftLeg ? 'leftFoot' : 'rightFoot', {
|
|
||||||
x: way.x * 4 * heroMoving,
|
|
||||||
y: way.y * 4 * heroMoving
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._animationFrame_weather = function (timestamp) {
|
control.prototype._animationFrame_weather = function (timestamp) {
|
||||||
@ -818,50 +813,56 @@ control.prototype.tryMoveDirectly = function (destX, destY) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
////// 绘制勇士 //////
|
////// 绘制勇士 //////
|
||||||
control.prototype.drawHero = function (status, offset, frame, noGather) {
|
control.prototype.drawHero = function (status, offset, frame) {
|
||||||
if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
|
if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
|
||||||
var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction');
|
var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction');
|
||||||
status = status || 'stop';
|
status = status || 'stop';
|
||||||
offset = offset || {};
|
if (!offset) offset = 0;
|
||||||
offset.x = offset.x || 0;
|
|
||||||
offset.y = offset.y || 0;
|
|
||||||
|
|
||||||
var way = core.utils.scan2[direction];
|
var way = core.utils.scan2[direction];
|
||||||
var dx = way.x, dy = way.y;
|
var dx = way.x, dy = way.y;
|
||||||
var offsetX = offset.x, offsetY = offset.y;
|
var offsetX = typeof offset == 'number' ? dx * offset : (offset.x || 0);
|
||||||
|
var offsetY = typeof offset == 'number' ? dy * offset : (offset.y || 0);
|
||||||
|
offset = {x: offsetX, y: offsetY, offset: offset};
|
||||||
|
|
||||||
core.clearAutomaticRouteNode(x + dx, y + dy);
|
core.clearAutomaticRouteNode(x + dx, y + dy);
|
||||||
core.clearMap('hero');
|
core.clearMap('hero');
|
||||||
core.status.heroCenter.px = 32 * x + offsetX + 16;
|
core.status.heroCenter.px = 32 * x + offsetX + 16;
|
||||||
core.status.heroCenter.py = 32 * y + offsetY + 32 - core.material.icons.hero.height / 2;
|
core.status.heroCenter.py = 32 * y + offsetY + 32 - core.material.icons.hero.height / 2;
|
||||||
|
|
||||||
this._drawHero_updateViewport(x, y, offset);
|
// 重置hero层画布
|
||||||
|
var px = parseFloat(core.canvas.hero.canvas.getAttribute('_px')) || 0;
|
||||||
|
var py = parseFloat(core.canvas.hero.canvas.getAttribute('_py')) || 0;
|
||||||
|
core.setGameCanvasTranslate('hero', 0, 0);
|
||||||
|
core.canvas.hero.canvas.removeAttribute('_px');
|
||||||
|
core.canvas.hero.canvas.removeAttribute('_py');
|
||||||
|
offset.px = px;
|
||||||
|
offset.py = py;
|
||||||
|
if (!core.hasFlag('__lockViewport__')) {
|
||||||
|
this._drawHero_updateViewport(x, y, offset);
|
||||||
|
}
|
||||||
|
|
||||||
if (!core.hasFlag('hideHero')) {
|
if (!core.hasFlag('hideHero')) {
|
||||||
this._drawHero_draw(direction, x, y, status, offset, frame, noGather);
|
this._drawHero_draw(direction, x, y, status, offset, frame);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._drawHero_updateViewport = function (x, y, offset) {
|
control.prototype._drawHero_updateViewport = function (x, y, offset) {
|
||||||
core.setGameCanvasTranslate('hero', 0, 0);
|
core.bigmap.offsetX = core.clamp((x - core.__HALF_SIZE__) * 32 + offset.x, 0, 32 * core.bigmap.width - core.__PIXELS__);
|
||||||
if (flags.__lockViewport__) return;
|
core.bigmap.offsetY = core.clamp((y - core.__HALF_SIZE__) * 32 + offset.y, 0, 32 * core.bigmap.height - core.__PIXELS__);
|
||||||
var offsetX = offset.x, offsetY = offset.y;
|
|
||||||
var ox = (x - core.__HALF_SIZE__) * 32 + offsetX,
|
|
||||||
oy = (y - core.__HALF_SIZE__) * 32 + offsetY;
|
|
||||||
|
|
||||||
core.bigmap.offsetX = core.clamp(ox, 0, 32 * core.bigmap.width - core.__PIXELS__);
|
|
||||||
core.bigmap.offsetY = core.clamp(oy, 0, 32 * core.bigmap.height - core.__PIXELS__);
|
|
||||||
core.control.updateViewport();
|
core.control.updateViewport();
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame, noGather) {
|
control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame) {
|
||||||
this._drawHero_getDrawObjs(direction, x, y, status, offset, noGather).forEach(function (block) {
|
offset = offset || {x: 0, y: 0, offset: 0, px: 0, py: 0};
|
||||||
|
this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) {
|
||||||
core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0))%4*block.width,
|
core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0))%4*block.width,
|
||||||
block.heroIcon.loc * block.height, block.width, block.height,
|
block.heroIcon.loc * block.height, block.width, block.height,
|
||||||
block.posx+(32-block.width)/2, block.posy+32-block.height, block.width, block.height);
|
offset.px+block.posx+(32-block.width)/2, offset.py+block.posy+32-block.height, block.width, block.height);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset, noGather) {
|
control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) {
|
||||||
var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0;
|
var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0;
|
||||||
drawObjs.push({
|
drawObjs.push({
|
||||||
"img": core.material.images.hero,
|
"img": core.material.images.hero,
|
||||||
@ -873,16 +874,15 @@ control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, off
|
|||||||
"status": status,
|
"status": status,
|
||||||
"index": index++,
|
"index": index++,
|
||||||
});
|
});
|
||||||
// 不重绘跟随者 比如说跳跃时……
|
if (typeof offset.offset == 'number') {
|
||||||
if (!noGather) {
|
|
||||||
core.status.hero.followers.forEach(function(t) {
|
core.status.hero.followers.forEach(function(t) {
|
||||||
drawObjs.push({
|
drawObjs.push({
|
||||||
"img": core.material.images.images[t.name],
|
"img": core.material.images.images[t.name],
|
||||||
"width": core.material.images.images[t.name].width / 4,
|
"width": core.material.images.images[t.name].width / 4,
|
||||||
"height": core.material.images.images[t.name].height / 4,
|
"height": core.material.images.images[t.name].height / 4,
|
||||||
"heroIcon": heroIconArr[t.direction],
|
"heroIcon": heroIconArr[t.direction],
|
||||||
"posx": 32 * t.x - core.bigmap.offsetX + (t.stop ? 0 : core.utils.scan2[t.direction].x * Math.abs(offset.x)),
|
"posx": 32 * t.x - core.bigmap.offsetX + (t.stop ? 0 : core.utils.scan2[t.direction].x * Math.abs(offset.offset)),
|
||||||
"posy": 32 * t.y - core.bigmap.offsetY + (t.stop ? 0 : core.utils.scan2[t.direction].y * Math.abs(offset.y)),
|
"posy": 32 * t.y - core.bigmap.offsetY + (t.stop ? 0 : core.utils.scan2[t.direction].y * Math.abs(offset.offset)),
|
||||||
"status": t.stop ? "stop" : status,
|
"status": t.stop ? "stop" : status,
|
||||||
"index": index++
|
"index": index++
|
||||||
});
|
});
|
||||||
@ -901,26 +901,27 @@ control.prototype.triggerHero = function (type, time, callback) {
|
|||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (type == 'show') core.removeFlag('hideHero');
|
core.removeFlag('hideHero');
|
||||||
else core.setFlag('hideHero', true);
|
|
||||||
|
|
||||||
time = time || 0;
|
var cb = function () {
|
||||||
if (time == 0) {
|
if (type == 'hide') core.setFlag('hideHero', true);
|
||||||
core.drawHero();
|
core.drawHero();
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
time = time || 0;
|
||||||
|
if (time == 0) return cb();
|
||||||
time /= Math.max(core.status.replay.speed, 1)
|
time /= Math.max(core.status.replay.speed, 1)
|
||||||
this._triggerHero_animate(type, 10 / time, callback);
|
this._triggerHero_animate(type, 10 / time, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
control.prototype._triggerHero_animate = function (type, delta, callback) {
|
control.prototype._triggerHero_animate = function (type, delta, callback) {
|
||||||
var opacity = type != 'show' ? 1 : 0;
|
var opacity = type != 'show' ? 1 : 0;
|
||||||
var animate = setInterval(function () {
|
var animate = setInterval(function () {
|
||||||
opacity += type != 'show' ? -delta : delta;
|
opacity += type != 'show' ? -delta : delta;
|
||||||
core.clearMap('hero');
|
|
||||||
core.setAlpha('hero', opacity);
|
core.setAlpha('hero', opacity);
|
||||||
core.control._drawHero_draw(core.getHeroLoc('direction'), core.getHeroLoc('x'), core.getHeroLoc('y'), 'stop', 0);
|
core.drawHero();
|
||||||
core.setAlpha('hero', 1);
|
core.setAlpha('hero', 1);
|
||||||
if (opacity >= 1 || opacity <= 0) {
|
if (opacity >= 1 || opacity <= 0) {
|
||||||
delete core.animateFrame.asyncId[animate];
|
delete core.animateFrame.asyncId[animate];
|
||||||
@ -1009,14 +1010,19 @@ control.prototype.updateViewport = function() {
|
|||||||
|
|
||||||
////// 设置视野范围 //////
|
////// 设置视野范围 //////
|
||||||
control.prototype.setViewport = function (px, py) {
|
control.prototype.setViewport = function (px, py) {
|
||||||
|
var originOffsetX = core.bigmap.offsetX, originOffsetY = core.bigmap.offsetY;
|
||||||
core.bigmap.offsetX = core.clamp(px, 0, 32 * core.bigmap.width - core.__PIXELS__);
|
core.bigmap.offsetX = core.clamp(px, 0, 32 * core.bigmap.width - core.__PIXELS__);
|
||||||
core.bigmap.offsetY = core.clamp(py, 0, 32 * core.bigmap.height - core.__PIXELS__);
|
core.bigmap.offsetY = core.clamp(py, 0, 32 * core.bigmap.height - core.__PIXELS__);
|
||||||
this.updateViewport();
|
this.updateViewport();
|
||||||
// ------ hero层也需要!
|
// ------ hero层也需要!
|
||||||
var hero_x = core.clamp((core.getHeroLoc('x') - core.__HALF_SIZE__) * 32, 0, 32*core.bigmap.width-core.__PIXELS__);
|
var canvas = core.canvas.hero.canvas;
|
||||||
var hero_y = core.clamp((core.getHeroLoc('y') - core.__HALF_SIZE__) * 32, 0, 32*core.bigmap.height-core.__PIXELS__);
|
var px = parseFloat(canvas.getAttribute('_px')) || 0;
|
||||||
core.control.setGameCanvasTranslate('hero', hero_x - core.bigmap.offsetX, hero_y - core.bigmap.offsetY);
|
var py = parseFloat(canvas.getAttribute('_py')) || 0;
|
||||||
|
px += originOffsetX - core.bigmap.offsetX;
|
||||||
|
py += originOffsetY - core.bigmap.offsetY;
|
||||||
|
core.control.setGameCanvasTranslate('hero', px, py);
|
||||||
|
core.canvas.hero.canvas.setAttribute('_px', px);
|
||||||
|
core.canvas.hero.canvas.setAttribute('_py', py);
|
||||||
}
|
}
|
||||||
|
|
||||||
////// 移动视野范围 //////
|
////// 移动视野范围 //////
|
||||||
|
|||||||
@ -788,6 +788,11 @@ events.prototype._changeFloor_beforeChange = function (info, callback) {
|
|||||||
|
|
||||||
events.prototype._changeFloor_changing = function (info, callback) {
|
events.prototype._changeFloor_changing = function (info, callback) {
|
||||||
this.changingFloor(info.floorId, info.heroLoc);
|
this.changingFloor(info.floorId, info.heroLoc);
|
||||||
|
// 回归视角
|
||||||
|
var __lockViewport__ = flags.__lockViewport__;
|
||||||
|
core.setFlag('__lockViewport__', null);
|
||||||
|
core.drawHero();
|
||||||
|
core.setFlag('__lockViewport__', __lockViewport__);
|
||||||
|
|
||||||
if (info.time == 0)
|
if (info.time == 0)
|
||||||
this._changeFloor_afterChange(info, callback);
|
this._changeFloor_afterChange(info, callback);
|
||||||
@ -1528,7 +1533,7 @@ events.prototype._action_setViewport = function (data, x, y, prefix) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._action_lockViewport = function (data, x, y, prefix) {
|
events.prototype._action_lockViewport = function (data, x, y, prefix) {
|
||||||
flags.__lockViewport__ = data.lock;
|
core.setFlag('__lockViewport__', data.lock || null);
|
||||||
core.doAction();
|
core.doAction();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3552,16 +3557,10 @@ events.prototype._eventMoveHero_moving = function (step, moveSteps) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (step <= 4) {
|
if (step <= 4) {
|
||||||
core.drawHero('leftFoot', {
|
core.drawHero('leftFoot', 4 * o * step);
|
||||||
x: 4 * o * step,
|
|
||||||
y: 4 * o * step
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
else if (step <= 8) {
|
else if (step <= 8) {
|
||||||
core.drawHero('rightFoot', {
|
core.drawHero('rightFoot', 4 * o * step);
|
||||||
x: 4 * o * step,
|
|
||||||
y: 4 * o * step
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
if (step == 8) {
|
if (step == 8) {
|
||||||
core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true);
|
core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true);
|
||||||
@ -3609,10 +3608,7 @@ events.prototype._jumpHero_jumping = function (jumpInfo) {
|
|||||||
var x = core.getHeroLoc('x'),
|
var x = core.getHeroLoc('x'),
|
||||||
y = core.getHeroLoc('y');
|
y = core.getHeroLoc('y');
|
||||||
var nowx = jumpInfo.px, nowy = jumpInfo.py, width = jumpInfo.width || 32, height = jumpInfo.height;
|
var nowx = jumpInfo.px, nowy = jumpInfo.py, width = jumpInfo.width || 32, height = jumpInfo.height;
|
||||||
core.drawHero(null, {
|
core.drawHero('stop', { x: nowx - 32 * x, y: nowy - 32 * y });
|
||||||
x: nowx - 32 * x,
|
|
||||||
y: nowy - 32 * y
|
|
||||||
}, 0, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
events.prototype._jumpHero_finished = function (animate, ex, ey, callback) {
|
events.prototype._jumpHero_finished = function (animate, ex, ey, callback) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user