Skip to content

Commit b8f0b59

Browse files
committed
Update _GameMaker.js
A possible solution to stuttering in mobile browser, mostly when the player touch the screen but not limited to that
1 parent 82718d0 commit b8f0b59

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

scripts/_GameMaker.js

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2272,34 +2272,7 @@ function GameMaker_Tick()
22722272
newfps = 0;
22732273
lastfpstime = g_CurrentTime;
22742274
}
2275-
newfps++;
22762275

2277-
// schedule next frame:
2278-
// this might be best done after if(!Run_Paused) block,
2279-
// but then an exception would halt the game loop.
2280-
var nextFrameAt = g_FrameStartTime + 1000 / TargetSpeed;
2281-
var now = Date.now();
2282-
var delay = g_FrameStartTime + 1000 / TargetSpeed - now;
2283-
if (delay < 0) delay = 0;
2284-
g_FrameStartTime = now + delay;
2285-
if (delay > 4) {
2286-
// 4ms is the general minimum timeout time as per spec,
2287-
// https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
2288-
setTimeout(function() {
2289-
if (window.yyRequestAnimationFrame) {
2290-
window.yyRequestAnimationFrame(animate);
2291-
} else {
2292-
// Don't re-enter, that would be bad.
2293-
//animate();
2294-
}
2295-
}, delay);
2296-
} else {
2297-
if (window.yyRequestAnimationFrame) {
2298-
window.yyRequestAnimationFrame(animate);
2299-
} else {
2300-
window.postMessage("yyRequestAnimationFrame", "*");
2301-
}
2302-
}
23032276

23042277
if (!Run_Paused)
23052278
{
@@ -2370,6 +2343,26 @@ function GameMaker_Tick()
23702343
g_MouseDeltaY = 0;
23712344
}
23722345

2346+
2347+
// schedule next frame:
2348+
// this might be best done after if(!Run_Paused) block,
2349+
// but then an exception would halt the game loop.
2350+
var nextFrameAt = g_FrameStartTime + 1000 / TargetSpeed;
2351+
var now = g_CurrentTime;
2352+
var delay = nextFrameAt - now;
2353+
if (delay < 0) delay = 0;
2354+
2355+
g_FrameStartTime += delay;
2356+
2357+
if (delay <= 4) {
2358+
if (window.yyRequestAnimationFrame) {
2359+
window.yyRequestAnimationFrame(animate);
2360+
} else {
2361+
window.postMessage("yyRequestAnimationFrame", "*");
2362+
}
2363+
}
2364+
newfps++;
2365+
23732366
// if in DEBUG mode, do debug "stuff"
23742367
// @if feature("debug")
23752368
if (g_pGMFile.Options && g_pGMFile.Options.debugMode) {

0 commit comments

Comments
 (0)