设为首页收藏本站|繁體中文

Project1

 找回密码
 注册会员
搜索
查看: 2902|回复: 4
打印 上一主题 下一主题

[交流讨论] 有办法锁定最高帧数吗

[复制链接]

Lv1.梦旅人

梦石
0
星屑
131
在线时间
143 小时
注册时间
2020-12-19
帖子
80
跳转到指定楼层
1
发表于 2021-1-24 15:56:17 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

加入我们,或者,欢迎回来。

您需要 登录 才可以下载或查看,没有帐号?注册会员

x
发现一个问题,在不同电脑或手机上,由于支持的最高刷新率不同,有90fps,144pfs的。然后结果就是游戏速度不同了,做的动画速度也不同了,请问这个问题有帮法解决吗?

Lv3.寻梦者

梦石
0
星屑
3453
在线时间
1159 小时
注册时间
2016-8-9
帖子
2390

开拓者

2
发表于 2021-1-24 16:27:45 | 只看该作者
YEP.81 – FPS Synch Option
有个同步插件,说明里面解释的是可以将性能不足的设备锁定帧数,不知道性能好的设备能不能锁定到60帧,楼主试验下,有结果的话请回来告知
酸酸甜甜就④哇噢
回复 支持 反对

使用道具 举报

Lv3.寻梦者

梦石
0
星屑
3461
在线时间
292 小时
注册时间
2020-1-27
帖子
190
3
发表于 2021-1-24 20:25:01 | 只看该作者
  1. /**
  2. * JshackJsGearOut v1.2
  3. *   By EtherDream
  4. */
  5.     if(window.hackJsGearOut === undefined){
  6.     var hackJsGearOut = (function(fnST, fnCT, fnSI, fnCI, fnDt, global) {
  7.         /**
  8.          * IE678:
  9.          *   => typeof window.setInterval == 'obecjt'
  10.          *   => window.setInterval = function(){...}        //错误
  11.          *
  12.          * 解决方法:
  13.          *   1. function setInterval(){}                                //在全局定义setInterval函数
  14.          *   2. window.setInterval = function(){...}        //可以覆盖
  15.          */
  16.         var execScript = window.execScript;
  17.         var STD = !!window.addEventListener;

  18.         function fixNative() {
  19.             execScript('function setTimeout(){}function clearTimeout(){}function setInterval(){}function clearInterval(){}');
  20.         }


  21.         var iRate = 1;
  22.         var iFreeFrame = 9e9;
  23.         var iLast, iTick;

  24.         var aQueue = [];
  25.         var nQueue = 1;
  26.         var iFlag = 0;


  27.         function addQueue(code, delay, arg, repeat) {
  28.             if (!code) {
  29.                 return;
  30.             }

  31.             // 参数类型验证
  32.             delay = +delay || 0;

  33.             if (delay < 1) {
  34.                 delay = 1;
  35.             }

  36.             // 添加任务队列
  37.             aQueue[nQueue] =
  38.                 {code:code, delay:delay, arg:arg, repeat:repeat, sum:0, flag:iFlag};

  39.             return nQueue++;
  40.         }

  41.         function delQueue(id) {
  42.             if (id >= 0) {
  43.                 delete aQueue[id];
  44.             }
  45.         }

  46.         function hook() {
  47.             global.setTimeout = setTimeout;
  48.             global.clearTimeout = clearTimeout;
  49.             global.setInterval = setInterval;
  50.             global.clearInterval = clearInterval;
  51.             global.Date = Date;

  52.             for (var i = 0; i < requestFrameName.length; i++) {
  53.                 global[requestFrameName[i]] = requestAnimationFrame;
  54.                 global[cancelFrameName[i]] = clearTimeout;
  55.             }

  56.             iLast = iTick = +new fnDt;
  57.             tid = fnSI(onTimer, 1);
  58.         }

  59.         function unhook() {
  60.             global.setTimeout = fnST;
  61.             global.clearTimeout = fnCT;
  62.             global.setInterval = fnSI;
  63.             global.clearInterval = fnCI;
  64.             global.Date = fnDt;

  65.             for (var i = 0; i < requestFrameName.length; i++) {
  66.                 var k = requestFrameName[i];
  67.                 global[k] = requestFrameFn[k];
  68.             }
  69.         }

  70.         function execute(task) {
  71.             var code = task.code;

  72.             if (typeof code == 'function') {
  73.                 if (execScript) {        // ie不支持参数传递
  74.                     code();
  75.                 }
  76.                 else {                                // 支持多参数传递
  77.                     task.arg ?
  78.                         code.apply(global, task.arg) :
  79.                         code();
  80.                 }
  81.             }
  82.             else {
  83.                 if (execScript) {                // ie可选择脚本语言
  84.                     task.arg ?
  85.                         execScript(code, task.arg[0]) :
  86.                         execScript(code);
  87.                 } else {                                // 全局执行
  88.                     global.eval(code);
  89.                 }
  90.             }
  91.         }


  92.         function onTimer() {
  93.             var cur = +new fnDt;
  94.             var elapse = (cur - iLast) * iRate;


  95.             for(var k in aQueue) {
  96.                 var task = aQueue[k];

  97.                 // 防止ie浏览器枚举时递归
  98.                 if (task.flag == iFlag) {
  99.                     continue;
  100.                 }

  101.                 // 计时器累加
  102.                 task.sum += elapse;

  103.                 if (task.repeat) {                // setInterval
  104.                     // 跳帧数
  105.                     var skip = (task.sum / task.delay) >> 0;

  106.                     // 最大跳帧数,防止卡死
  107.                     if (skip > 32) {
  108.                         skip = 32;
  109.                     }

  110.                     // 执行每一帧
  111.                     while (--skip >= 0) {
  112.                         execute(task);
  113.                     }

  114.                     // 剩余点数
  115.                     task.sum %= task.delay;
  116.                 }
  117.                 else {                                // setTimeout
  118.                     if (task.sum >= task.delay) {
  119.                         execute(task);

  120.                         delete aQueue[k];
  121.                         continue;
  122.                     }
  123.                 }
  124.             }

  125.             iLast = cur;
  126.             iTick += elapse;
  127.             iFlag++;
  128.         }


  129.         /** 重定义时间函数 ***********************************/
  130.         var SLICE = [].slice;

  131.         function setTimeout(code, delay, arg) {
  132.             if (arg) {
  133.                 arg = SLICE.call(arguments, 2);
  134.             }
  135.             return addQueue(code, delay, arg, false);
  136.         }

  137.         function clearTimeout(id) {
  138.             delQueue(id);
  139.         }

  140.         function setInterval(code, delay, arg) {
  141.             if (arg) {
  142.                 arg = SLICE.call(arguments, 2);
  143.             }
  144.             return addQueue(code, delay, arg, true);
  145.         }

  146.         function clearInterval(id) {
  147.             delQueue(id);
  148.         }

  149.         function requestAnimationFrame(cb) {
  150.             return setTimeout(cb, 16);
  151.         }


  152.         var requestFrameName = [],
  153.             requestFrameFn = {},
  154.             cancelFrameName = [],
  155.             cancelFrameFn = {};



  156.         var REQUEST_FRAME = [
  157.             'oRequestAnimationFrame',
  158.             'mozRequestAnimationFrame',
  159.             'webkitRequestAnimationFrame',
  160.             'msRequestAnimationFrame',
  161.             'requestAnimationFrame'
  162.         ];

  163.         var CANCEL_FRAME = [
  164.             'cancelAnimationFrame',
  165.             'cancelRequestAnimationFrame',
  166.             'mozCancelAnimationFrame',
  167.             'mozCancelRequestAnimationFrame',
  168.             'webkitCancelAnimationFrame',
  169.             'webkitCancelRequestAnimationFrame',
  170.             'oCancelAnimationFrame',
  171.             'oCancelRequestAnimationFrame',
  172.             'msCancelAnimationFrame',
  173.             'msCancelRequestAnimationFrame'
  174.         ];

  175.         for(var i = REQUEST_FRAME.length - 1; i >= 0; i--) {
  176.             var k = REQUEST_FRAME[i];
  177.             if (global[k]) {
  178.                 requestFrameName.push(k);
  179.                 requestFrameFn[k] = global[k];
  180.             }

  181.             k = CANCEL_FRAME[i];
  182.             if (global[k]) {
  183.                 cancelFrameName.push(k);
  184.                 cancelFrameFn[k] = global[k];
  185.             }
  186.         }


  187.         // ==================================================
  188.         // 重定义 Date
  189.         // ==================================================
  190.         function Date(y, m, d, h, min, s, ms) {
  191.             if (this instanceof Date) {                // new Date(...)
  192.                 switch(arguments.length) {
  193.                 case 0:
  194.                     var cur = +new fnDt;
  195.                     iTick += (cur - iLast) * iRate;
  196.                     iLast = cur;
  197.                     return new fnDt(iTick);

  198.                 case 1: return new fnDt(y);
  199.                 case 2:        return new fnDt(y, m);
  200.                 case 3:        return new fnDt(y, m, d);
  201.                 case 4:        return new fnDt(y, m, d, h);
  202.                 case 5:        return new fnDt(y, m, d, h, min);
  203.                 case 6:        return new fnDt(y, m, d, h, min, s);
  204.                 default:return new fnDt(y, m, d, h, min, s, ms);
  205.                 }
  206.             }
  207.             else {                                                        // Date()
  208.                 // ie678的Date()返回值里没有UTC+0800
  209.                 return STD ?
  210.                     new Date().toString() :
  211.                     new Date().toString().replace(/UTC.+ /, '');
  212.             }
  213.         }


  214.         if (fnDt.now) Date.now = function() {
  215.             var cur = fnDt.now();
  216.             iTick += (cur - iLast) * iRate;
  217.             iLast = cur;
  218.             return Math.round(iTick);
  219.         };

  220.         Date.UTC = fnDt.UTC;
  221.         Date.parse = fnDt.parse;
  222.         Date.prototype = fnDt.prototype;



  223.         // ==================================================
  224.         // 导出接口
  225.         // ==================================================
  226.         var nativeFn = (typeof fnCT == 'object');

  227.         function setup() {
  228.             if (nativeFn) {
  229.                 fixNative();
  230.             }
  231.             hook();
  232.         }

  233.         function unsetup() {
  234.             unhook();
  235.         }

  236.         function setRate(rate) {
  237.             iRate = rate;
  238.         }

  239.         function pause() {
  240.             iFreeFrame = 0;
  241.         }

  242.         function resume() {
  243.             iFreeFrame = 9e9;
  244.         }

  245.         function next(count) {
  246.             iFreeFrame = count || 1;
  247.         }

  248.         setup();

  249.         return {
  250.             setup: setup,
  251.             unsetup: unsetup,
  252.             setRate: setRate,
  253.             pause: pause,
  254.             resume: resume,
  255.             next: next,

  256.             rawSetTimeout: nativeFn? fnST : function() {return fnST.apply(global, arguments)},
  257.             rawClearTimeout: nativeFn? fnCT : function() {return fnCT.apply(global, arguments)},
  258.             rawSetInterval: nativeFn? fnSI : function() {return fnSI.apply(global, arguments)},
  259.             rawClearInterval: nativeFn? fnCI : function() {return fnCI.apply(global, arguments)}
  260.         };
  261.     })
  262.     (
  263.         setTimeout,
  264.         clearTimeout,
  265.         setInterval,
  266.         clearInterval,
  267.         Date,
  268.         this
  269.     );
  270. }
复制代码

这个也能限帧...
调速功能倒是没啥用.不好使.反正能限制到60上下

评分

参与人数 1+1 收起 理由
白嫩白嫩的 + 1 666666

查看全部评分

回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
131
在线时间
143 小时
注册时间
2020-12-19
帖子
80
4
 楼主| 发表于 2021-1-26 17:16:02 | 只看该作者
白嫩白嫩的 发表于 2021-1-24 16:27
YEP.81 – FPS Synch Option
有个同步插件,说明里面解释的是可以将性能不足的设备锁定帧数,不知道性能好 ...

这个一开好卡..好奇怪
回复 支持 反对

使用道具 举报

Lv1.梦旅人

梦石
0
星屑
131
在线时间
143 小时
注册时间
2020-12-19
帖子
80
5
 楼主| 发表于 2021-1-26 17:16:59 | 只看该作者
zths 发表于 2021-1-24 20:25
这个也能限帧...
调速功能倒是没啥用.不好使.反正能限制到60上下

谢谢大佬,我去试试
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

拿上你的纸笔,建造一个属于你的梦想世界,加入吧。
 注册会员
找回密码

站长信箱:[email protected]|手机版|小黑屋|无图版|Project1游戏制作

GMT+8, 2024-4-25 17:35

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表