【oops-framework】时间管理

功能说明

OopsFramework-时间管理模块主要实现在游戏中不同类型的定时器功能。

使用说明

获取游戏开始到现在逝去的时间
oops.timer.getTime();
获取本地时间刻度
oops.timer.getLocalTime();
注册一个固定间隔时间的触发器
oops.timer.schedule(()=>{
    // 每秒触发一次
}, 1000);
注册一个只触发一次的延时的触发器
oops.timer.scheduleOnce(()=>{
    // 1秒后触发一次后不会在触发
}, 1000);
删除一个时间触发器
var uuid = oops.timer.schedule(()=>{
    // 每秒触发一次
}, 1000);

// 删除指定标识的触发器
oops.timer.unschedule(uuid);
删除所有时间触发器
oops.timer.unscheduleAll();
在指定对象上注册一个倒计时的回调管理器
export class Test extends Component {
    private timeId!: string;
    
    start() {
        // 在指定对象上注册一个倒计时的回调管理器
        this.timeId = oops.timer.register(this, "countDown", this.onSecond, this.onComplete);
    }
    
    private onSecond() {
        console.log("每秒触发一次");
    }

    private onComplete() {
        console.log("倒计时完成触发");
    }
}
在指定对象上注销一个倒计时的回调管理器
export class Test extends Component {
    private timeId!: string;
    
    start() {
        this.timeId = oops.timer.register(this, "countDown", this.onSecond, this.onComplete);
    }
    
    onDestroy() {
        // 在指定对象上注销一个倒计时的回调管理器
        oops.timer.unRegister(this.timeId);
    }
}
定时跳动组件
export class Test extends Component {
    // 创建一个定时跳动组件
    private timer: Timer = new Timer(1);

    update(dt: number) {
        if (this.timer.update(this.dt)) {
            console.log(每一秒触发一次);
        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值