javascript - js - 仅在 x 秒后进行更改
问题描述
我做了这个脚本:
setInterval(myTimer, 1000);
function myTimer() {
const player = PlayerId()
const ped = GetPlayerPed(player);
const [playerX, playerY, playerZ] = GetEntityCoords(ped);
coordsX(playerX)
coordsY(playerY)
coordsZ(playerZ)
setTimeout(() => {
coordsX(playerX);
coordsY(playerY);
coordsZ(playerZ);
}, 5000);
}
基本上,它每秒都会更改 coordsX、coordsY 和 coordsZ 函数,但问题是文本不会在屏幕上停留超过一个刻度,并且它只会在一秒钟后再次显示,再次只有一个刻度。我想要它使文本保持打开并冻结一秒钟,然后再次重新加载。
这是其余的代码(即上面):
const height = 0.780
const beginning = 0.020
const add = 0.050
function coordsX(coordsX) {
SetTextFont(0);
SetTextProportional(1);
SetTextScale(0.0, 0.3);
SetTextColour(26, 255, 0, 255);
SetTextDropshadow(0, 0, 0, 0, 255);
SetTextEdge(1, 0, 0, 0, 255);
SetTextDropShadow();
SetTextOutline();
SetTextEntry("STRING");
AddTextComponentString('X: ' + coordsX.toFixed(2));
DrawText(beginning, height);
}
function coordsY(coordsY) {
SetTextFont(0);
SetTextProportional(1);
SetTextScale(0.0, 0.3);
SetTextColour(26, 255, 0, 255);
SetTextDropshadow(0, 0, 0, 0, 255);
SetTextEdge(1, 0, 0, 0, 255);
SetTextDropShadow();
SetTextOutline();
SetTextEntry("STRING");
AddTextComponentString('Y: ' + coordsY.toFixed(2));
DrawText(beginning + add, height);
}
function coordsZ(coordsZ) {
SetTextFont(0);
SetTextProportional(1);
SetTextScale(0.0, 0.3);
SetTextColour(26, 255, 0, 255);
SetTextDropshadow(0, 0, 0, 0, 255);
SetTextEdge(1, 0, 0, 0, 255);
SetTextDropShadow();
SetTextOutline();
SetTextEntry("STRING");
AddTextComponentString('Z: ' + coordsZ.toFixed(2));
DrawText(beginning + add*2, height);
}
解决方案
推荐阅读
- python-3.x - 使用不带 from 的相对导入
- r - 在R中按符号拆分数据帧中的字符串
- reactjs - React Native - 如何从屏幕传递到另一个屏幕?
- heroku - 没有 RedisToGo 附加组件的 Heroku 上的 Redis
- javascript - 将两个字符串组合在一起
- asp.net-mvc - AppVeyor CI - Azure 应用服务多环境部署
- regex - django中命名组url中匹配正则表达式的顺序
- c# - 发布文件是否足以运行 WPF 应用程序?
- parse-server - 在 Parse SDK 中 saveEventually 有时仅在应用重新加载时保存
- node.js - 如何使用 Mongoose 从具有关系/条件的集合中查找特定文档