保持游戏运行时,SWICH浏览器选项卡 [英] Keep game running when swich browser tab

查看:170
本文介绍了保持游戏运行时,SWICH浏览器选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作在空闲的比赛。当我切换浏览器选项卡或做点别的游戏失去焦点。我想保持游戏的运行,当我切换浏览器选项卡或做其他事。我搜索的谷歌,但我没有找到答案。

I work on an idle game. When I switch browser tab or do something else the game lose focus. I want to keep the game running when I switch browser tab or do something else. I searched on google but I didn't find an answer.

我怎么能这样做?(对不起,我的英语)

How can I do that?(sorry for my english)

推荐答案

您无法控制它。这是一个坏主意,依靠稳定的帧时间呢。而且不只是因为PC的速度会影响帧率。

You can't control it. And it's a bad idea to rely on stable frame times anyway. And not just because the speed of a the PC can affect the frame rate.

你平时做什么,而不是使用增量时间:

What you usually do instead is using delta time:

  • Is this a good implementation of the gameloop
  • http://en.wikipedia.org/wiki/Delta_timing

基本上每个刻度/帧你衡量,因为最后一跳/帧过了多少时间,并根据所持续的时间,然后计算进度。

Basically on every tick/frame you measure how much time passed by since the last tick/frame and then calculate progress depending on that duration.

编辑:

要回答你的第一个问题,你可以用同样的方法进行帧作为坐标。主要的区别是,当你使用框架,你居然跟整数时工作的DisplayObject坐标采用浮点值。由于整数是太不准确描述的方法,你应该使用一个内部浮点(:号码)可变,适用所有的计算上浮点变量,最后使用Math.round()的值来获得实际的帧数

To answer your first question, you can use the same method for frames as for coordinates. The main difference is that when you use frames, you actually work with integers while displayobject coordinates are using floating point values. Since integers are too inaccurate for the method described, you should use an internal floating point (":Number") variable, apply all calculations on that floating point variable and finally use Math.round() on the value to get the actual frame number.

编辑2:

下面一些非常基本未经测试 code:

[variable definition]
var floatingNumberFrame:Number=1;

[code in loop]
floatingNumberFrame+=speed*deltaTime;
if(floatingNumberFrame>=101){
    floatingNumberFrame=floatingNumberFrame%100;
}
theMovie.gotoAndStop(Math.round(floatingNumberFrame));

这篇关于保持游戏运行时,SWICH浏览器选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆