gpt4 book ai didi

javascript - Chrome网络应用程序: Cannot execute function in game loop

转载 作者:行者123 更新时间:2023-11-28 16:10:14 25 4
gpt4 key购买 nike

我是 Chrome Web Apps 的初学者,正在尝试将 Bump'n'Jump 的 JavaScript/HTML5 克隆打包为打包应用程序。我在 Chrome 的安全政策方面遇到了困难:

function pump() {
while (1) {

game_loop();
var now = timeGetTime();
var time_diff = next_time - now;
next_time += (1000 / 60);

if (time_diff>0) {
// we have time left
setTimeout("pump()", time_diff);
break;
}
// debug("frametime exceeded: " + (-time_diff));
}
}

它拒绝运行setTimeout("pump()", time_diff);,说

Refused to evaluate script because it violates the following Content Security Policy      directive: "default-src 'self' chrome-extension-resource:". Note that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

错误不在于代码,因为它在 Chrome 之外的浏览器中运行,Chrome 的安全性似乎不喜欢它。谁能告诉我为什么它不想运行 pump()

最佳答案

不知道这是否有帮助,但请尝试以下操作:替换 setTimeout 字符串参数:

function pump() {
while (1) {

game_loop();
var now = timeGetTime();
var time_diff = next_time - now;
next_time += (1000 / 60);

if (time_diff>0) {
// we have time left
setTimeout(pump, time_diff);
break;
}
// debug("frametime exceeded: " + (-time_diff));
}
}

setTimeoutsetInterval 中使用字符串作为执行参数相当于 eval,被认为是不好的做法。

关于javascript - Chrome网络应用程序: Cannot execute function in game loop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13188726/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com