diff --git a/docs/articles/uiintroduction.md b/docs/articles/uiintroduction.md index 1bcc2918d..1057a53ee 100644 --- a/docs/articles/uiintroduction.md +++ b/docs/articles/uiintroduction.md @@ -116,7 +116,8 @@ if ( SceneManager::instance()->getUISceneNode()->invalidated() ) { // Display the scene to the screen. win->display(); } else { - Sys::sleep( Milliseconds( 8 ) ); + // For for an input event or timeout after 16ms if has focus, otherwise wait 100ms. + win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); } ``` diff --git a/src/examples/ui_hello_world/ui_hello_world.cpp b/src/examples/ui_hello_world/ui_hello_world.cpp index 63aeb2f1d..715d7e75a 100644 --- a/src/examples/ui_hello_world/ui_hello_world.cpp +++ b/src/examples/ui_hello_world/ui_hello_world.cpp @@ -23,9 +23,13 @@ void mainLoop() { // Redraw the UI scene. SceneManager::instance()->draw(); + // Display the scene to the screen. win->display(); } else { - Sys::sleep( Milliseconds( 8 ) ); +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN + // For for an input event or timeout after 16ms if has focus, otherwise wait 100ms. + win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); +#endif } } diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index fd785144d..9566ab993 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -478,7 +478,9 @@ void App::mainLoop() { firstFrame = false; } } else { +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) ); +#endif } if ( mBenchmarkMode && mSecondsCounter.getElapsedTime() >= Seconds( 1 ) ) { diff --git a/src/tools/mapeditor/mapeditor.cpp b/src/tools/mapeditor/mapeditor.cpp index cd681c5f1..83c8fd75d 100644 --- a/src/tools/mapeditor/mapeditor.cpp +++ b/src/tools/mapeditor/mapeditor.cpp @@ -69,7 +69,9 @@ void mainLoop() { win->display(); } else { - Sys::sleep( Milliseconds( 8 ) ); +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN + win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); +#endif } } @@ -91,7 +93,7 @@ EE_MAIN_FUNC int main( int, char*[] ) { if ( win->isOpen() ) { PixelDensity::setPixelDensity( eemax( win->getScale(), pixelDensity ) ); - win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) ); + win->setCloseRequestCallback( onCloseRequestCallback ); UISceneNode* uiSceneNode = UISceneNode::New(); diff --git a/src/tools/textureatlaseditor/textureatlaseditor.cpp b/src/tools/textureatlaseditor/textureatlaseditor.cpp index a3516dce7..9542c7b18 100644 --- a/src/tools/textureatlaseditor/textureatlaseditor.cpp +++ b/src/tools/textureatlaseditor/textureatlaseditor.cpp @@ -69,7 +69,9 @@ void mainLoop() { win->display(); } else { - Sys::sleep( Milliseconds( 8 ) ); +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN + win->getInput()->waitEvent( Milliseconds( win->hasFocus() ? 16 : 100 ) ); +#endif } } @@ -91,7 +93,7 @@ EE_MAIN_FUNC int main( int, char*[] ) { if ( win->isOpen() ) { PixelDensity::setPixelDensity( eemax( win->getScale(), pixelDensity ) ); - win->setCloseRequestCallback( cb::Make1( onCloseRequestCallback ) ); + win->setCloseRequestCallback( onCloseRequestCallback ); UISceneNode* uiSceneNode = UISceneNode::New(); diff --git a/src/tools/uieditor/uieditor.cpp b/src/tools/uieditor/uieditor.cpp index 43a7716bb..489595651 100644 --- a/src/tools/uieditor/uieditor.cpp +++ b/src/tools/uieditor/uieditor.cpp @@ -937,7 +937,9 @@ void App::mainLoop() { mWindow->display(); } else { +#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN mWindow->getInput()->waitEvent( Milliseconds( mWindow->hasFocus() ? 16 : 100 ) ); +#endif } }