mirror of
https://github.com/unanmed/HumanBreak.git
synced 2025-01-19 20:59:37 +08:00
平滑移动镜头
This commit is contained in:
parent
f72d2161e5
commit
a61952034a
@ -18,6 +18,7 @@ import completion, { floors } from './plugin/completion';
|
||||
import path from './plugin/fx/path';
|
||||
import gameCanvas from './plugin/fx/gameCanvas';
|
||||
import noise from './plugin/fx/noise';
|
||||
import smooth from './plugin/fx/smoothView';
|
||||
|
||||
function forward() {
|
||||
const toForward: any[] = [
|
||||
@ -40,7 +41,8 @@ function forward() {
|
||||
completion(),
|
||||
path(),
|
||||
gameCanvas(),
|
||||
noise()
|
||||
noise(),
|
||||
smooth()
|
||||
];
|
||||
|
||||
// 初始化所有插件,并转发到core上
|
||||
|
63
src/plugin/fx/smoothView.ts
Normal file
63
src/plugin/fx/smoothView.ts
Normal 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);
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user