plugin - smoothCamera
This commit is contained in:
parent
12cdb8c47a
commit
20d047bb18
@ -84,5 +84,150 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 =
|
||||
ctx.globalCompositeOperation = 'source-over';
|
||||
// 可以在任何地方(如afterXXX或自定义脚本事件)调用函数,方法为 core.plugin.xxx();
|
||||
}
|
||||
},
|
||||
"smoothCamera": function () {
|
||||
|
||||
this.Camera = function () {
|
||||
|
||||
// 下面这个变量决定本插件的开关
|
||||
// 你可以在游戏中使用core.setFlag('smoothCamera',false)来关闭本插件的功能
|
||||
// 同时也可以core.setFlag('smoothCamera',true)重新开启
|
||||
// 本插件默认开启
|
||||
//
|
||||
this.__switchName = 'smoothCamera';
|
||||
|
||||
// 初始化成员变量
|
||||
this._cameraNeedRefresh = true;
|
||||
this._nowOffsetX = 0;
|
||||
this._nowOffsetY = 0;
|
||||
this._targetOffsetX = 0;
|
||||
this._targetOffsetY = 0;
|
||||
this._currentFloorId = null;
|
||||
|
||||
// 重置镜头,在楼层变更时使用
|
||||
this.resetCamera = function () {
|
||||
this._targetOffsetX = core.bigmap.offsetX;
|
||||
this._targetOffsetY = core.bigmap.offsetY;
|
||||
this._nowOffsetX = this._targetOffsetX;
|
||||
this._nowOffsetY = this._targetOffsetY;
|
||||
this._cameraNeedRefresh = true;
|
||||
};
|
||||
|
||||
// 设置焦点坐标,目前没有用
|
||||
this.setTarget = function (x, y) {
|
||||
this._targetOffsetX = x;
|
||||
this._targetOffsetY = y;
|
||||
};
|
||||
|
||||
// 请求镜头更新
|
||||
this.requestCameraUpdate = function () {
|
||||
this._cameraNeedRefresh = true;
|
||||
};
|
||||
|
||||
// 更新焦点坐标,目前仅根据大地图偏移决定
|
||||
this.updateTargetPosition = function () {
|
||||
this._targetOffsetX = core.bigmap.offsetX;
|
||||
this._targetOffsetY = core.bigmap.offsetY;
|
||||
};
|
||||
|
||||
// 更新额外的刷新条件,即镜头未指向焦点时
|
||||
this.updateRefreshFlag = function () {
|
||||
if (this._nowOffsetX != this._targetOffsetX || this._nowOffsetY != this._targetOffsetY) {
|
||||
this._cameraNeedRefresh = true;
|
||||
}
|
||||
};
|
||||
|
||||
// 判断是否禁止了弹性滚动
|
||||
this.canDirectMove = function () {
|
||||
return !core.getFlag(this.__switchName, true);
|
||||
};
|
||||
|
||||
// 更新镜头坐标
|
||||
this.updateCameraPosition = function () {
|
||||
if (this._cameraNeedRefresh) {
|
||||
this._cameraNeedRefresh = false;
|
||||
var disX = this._targetOffsetX - this._nowOffsetX;
|
||||
var disY = this._targetOffsetY - this._nowOffsetY;
|
||||
if (Math.abs(disX) <= 2 && Math.abs(disY) <= 2 || this.canDirectMove()) {
|
||||
this._nowOffsetX = this._targetOffsetX;
|
||||
this._nowOffsetY = this._targetOffsetY;
|
||||
} else {
|
||||
this._nowOffsetX += disX / 10;
|
||||
this._nowOffsetY += disY / 10;
|
||||
}
|
||||
var x = -Math.floor(this._nowOffsetX);
|
||||
var y = -Math.floor(this._nowOffsetY);
|
||||
core.bigmap.canvas.forEach(function (cn) {
|
||||
core.control.setGameCanvasTranslate(cn, x, y);
|
||||
});
|
||||
core.relocateCanvas('route', core.status.automaticRoute.offsetX + x, core.status.automaticRoute.offsetY + y);
|
||||
core.setGameCanvasTranslate('hero', x + this._targetOffsetX, y + this._targetOffsetY);
|
||||
}
|
||||
};
|
||||
|
||||
// 更新逻辑主体
|
||||
this.update = function () {
|
||||
this.updateTargetPosition();
|
||||
this.updateRefreshFlag();
|
||||
this.updateCameraPosition();
|
||||
};
|
||||
};
|
||||
|
||||
// 其实只注释了最后一行,只能这样了
|
||||
control.drawHero = function (status, offset) {
|
||||
if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
|
||||
var x = core.getHeroLoc('x'),
|
||||
y = core.getHeroLoc('y'),
|
||||
direction = core.getHeroLoc('direction');
|
||||
status = status || 'stop';
|
||||
offset = offset || 0;
|
||||
var way = core.utils.scan[direction];
|
||||
var dx = way.x,
|
||||
dy = way.y,
|
||||
offsetX = dx * offset,
|
||||
offsetY = dy * offset;
|
||||
core.bigmap.offsetX = core.clamp((x - core.__HALF_SIZE__) * 32 + offsetX, 0, 32 * core.bigmap.width - core.__PIXELS__);
|
||||
core.bigmap.offsetY = core.clamp((y - core.__HALF_SIZE__) * 32 + offsetY, 0, 32 * core.bigmap.height - core.__PIXELS__);
|
||||
core.clearAutomaticRouteNode(x + dx, y + dy);
|
||||
core.clearMap('hero');
|
||||
|
||||
if (!core.hasFlag('hideHero')) {
|
||||
this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) {
|
||||
core.drawImage('hero', block.img, block.heroIcon[block.status] * block.width,
|
||||
block.heroIcon.loc * block.height, block.width, block.height,
|
||||
block.posx + (32 - block.width) / 2, block.posy + 32 - block.height, block.width, block.height);
|
||||
});
|
||||
}
|
||||
|
||||
core.control.updateViewport();
|
||||
//core.setGameCanvasTranslate('hero', 0, 0);
|
||||
};
|
||||
|
||||
// 复写转发
|
||||
core.drawHero = function (status, offset) {
|
||||
return core.control.drawHero(status, offset);
|
||||
};
|
||||
|
||||
// 创建摄像机对象
|
||||
this.camera = new this.Camera();
|
||||
|
||||
// 帧事件 更新摄像机
|
||||
this.updateCameraEx = function () {
|
||||
this.camera.update();
|
||||
};
|
||||
|
||||
// 代理原本的镜头事件
|
||||
control.updateViewport = function () {
|
||||
core.plugin.camera.requestCameraUpdate();
|
||||
};
|
||||
|
||||
// 更变楼层的行为追加,重置镜头
|
||||
events.prototype.changingFloor = function (floorId, heroLoc, fromLoad) {
|
||||
this.eventdata.changingFloor(floorId, heroLoc, fromLoad);
|
||||
core.plugin.camera.resetCamera();
|
||||
};
|
||||
|
||||
// 注册帧事件
|
||||
core.registerAnimationFrame('smoothCameraFlash', true, this.updateCameraEx.bind(this));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user