请问项目组有计划加入这个功能吗? 看了下好像比较容易实现。
源代码我看过了 , 这里很好改。 但是自己改了源代码 下次Creator升级。 又得改。 我没搞清楚 官方为什么自己不加这个基础功能, 看起来很简单。
有在计划实现一个通用的计时器哦,只是目前任务比较多,这个优先级低一些
感觉在director直接加个属性timescale 对外暴露一个set就可以。 mainloop里面dt 乘以 timescale就可以。 设计通用计时器是打算更好扩展吗? 这块感觉是个挺固定需求 没什么需要扩展机会。
还有很多子系统,例如物理、缓动、动画这些
期待一波
任务多是理由吗?任务多就招人啊!
我正好在找工作,3k包吃就行。
4赞
cc.director.calculateDeltaTime = function (now) {
if (!now) now = performance.now();
this._deltaTime = (now - this._lastUpdate) / 1000;
this._deltaTime *= THE_SPEED_YOU_NEED;
this._lastUpdate = now;
}
2赞
var timeScale = 1;
//@ts-ignore
cc.game._calculateDT = function (now: number){ //游戏速率
if (!now) now = performance.now();
this._deltaTime = now > this._startTime ? (now - this._startTime) / 1000 : 0;
if(this._deltaTime > cc.Game.DEBUG_DT_THRESHOLD){
this._deltaTime = this.frameTime / 1000;
}
this._startTime = now;
return this._deltaTime * timescale;
};
public set TimeScale(v:number){
if(JSB){ //原生平台改变spine动画timescale
// @ts-ignore
cc.sp.spine.SkeletonAnimation.setGlobalTimeScale(v);
}
timescale = v;
}
3.x的方法
这我自用的,使用方式:slomo(0.5); /* 减速一半。 */
import { Director } from "cc";
const getOrCreateSlomoPolyfill = (() => {
let polyfill: undefined | { multiplier: number; };
return () => {
if (!polyfill) {
const polyfill_ = { multiplier: 1.0 };
const tick = Director.prototype.tick;
Director.prototype.tick = function(dt: number, ...args) {
tick.call(this, dt * polyfill_.multiplier, ...args);
};
polyfill = polyfill_;
}
return polyfill;
};
})();
export function slomo(multiplier: number) {
getOrCreateSlomoPolyfill().multiplier = multiplier;
}