gamelab / kiwi.js

Kiwi.js is a blazingly fast mobile & desktop browser based HTML5 game framework. It uses CocoonJS for publishing to the AppStore.
www.kiwijs.org
MIT License
1.41k stars 194 forks source link

`Utils.RequestAnimationFrame.stop()` doesn't work from inside KiwiJS #272

Closed BenjaminDRichards closed 8 years ago

BenjaminDRichards commented 8 years ago

It's rare, but for power or processor concerns, some game applications may wish to suspend all game functionality until an event triggers fresh updates. To do this, we should call stop() on the RAF.

However, this logic doesn't work inside KiwiJS.

The reason: Kiwi logic is all evaluated during Game._loop(). This is executed during the RAF method RAFUpdate(). Later in RAFUpdate(), a new RAF is made, with a new _rafId value. The RAF method stop() will cancel the current RAF, but has no way of interrupting the creation of the new RAF.

When stop() is called from a non-KiwiJS logic path, such as the browser console, it is not evaluated during RAFUpdate(), so the current RAF is cancelled and a new RAF is not created.

We should make stop() actually work.

BenjaminDRichards commented 8 years ago

I've added isRunning checks to the new RAF process. This way, stoppage will genuinely interrupt the flow. It is now possible to stop the RAF from the inside.