平滑移动镜头

This commit is contained in:
unanmed 2023-07-28 10:28:59 +08:00
parent f72d2161e5
commit a61952034a
2 changed files with 66 additions and 1 deletions

View File

@ -18,6 +18,7 @@ import completion, { floors } from './plugin/completion';
import path from './plugin/fx/path'; import path from './plugin/fx/path';
import gameCanvas from './plugin/fx/gameCanvas'; import gameCanvas from './plugin/fx/gameCanvas';
import noise from './plugin/fx/noise'; import noise from './plugin/fx/noise';
import smooth from './plugin/fx/smoothView';
function forward() { function forward() {
const toForward: any[] = [ const toForward: any[] = [
@ -40,7 +41,8 @@ function forward() {
completion(), completion(),
path(), path(),
gameCanvas(), gameCanvas(),
noise() noise(),
smooth()
]; ];
// 初始化所有插件并转发到core上 // 初始化所有插件并转发到core上

View File

@ -0,0 +1,63 @@
import { debounce } from 'lodash-es';
import { Transition, hyper } from 'mutate-animate';
const tran = new Transition();
tran.value.x = 0;
tran.value.y = 0;
let needSmooth = false;
export default function init() {
tran.ticker.add(() => {
if (core.isPlaying() && needSmooth) {
core.setViewport(tran.value.x, tran.value.y);
}
});
const func = debounce(() => {
needSmooth = false;
}, 700);
control.prototype._drawHero_updateViewport = function (
x: number,
y: number,
offset: Loc
) {
const ox = core.clamp(
(x - core._HALF_WIDTH_) * 32 + offset.x,
0,
Math.max(32 * core.bigmap.width - core._PX_, 0)
);
const oy = core.clamp(
(y - core._HALF_HEIGHT_) * 32 + offset.y,
0,
Math.max(32 * core.bigmap.height - core._PY_, 0)
);
tran.transition('x', ox).transition('y', oy);
needSmooth = true;
func();
};
let time2 = Date.now();
const origin1 = control.prototype._moveAction_moving;
control.prototype._moveAction_moving = function (...params: any[]) {
if (Date.now() - time2 > 20)
tran.mode(hyper('sin', 'out')).time(200).absolute();
origin1.call(this, ...params);
};
const origin2 = control.prototype.moveDirectly;
control.prototype.moveDirectly = function (...params: any[]) {
time2 = Date.now();
tran.mode(hyper('sin', 'out')).time(600).absolute();
origin2.call(this, ...params);
};
const origin3 = events.prototype._changeFloor_beforeChange;
events.prototype._changeFloor_beforeChange = function (...params: any[]) {
tran.time(1).absolute();
origin3.call(this, ...params);
};
}