I have a pixi graphic, which I animate.
I would like the animation ton continue even when the browser is minimised or the tab is no longer the "active" tab.
How do I do this? Currently all animation is paused when the browser focus is lost?
There's not much you can do about this, really. The ticker used in pixi uses requestAnimationFrame, which is the browser api that allows you to setup a callback each time the browser wants to draw to the screen. On most monitors, therefore, the callback occurs 60 times a second. But to save cpu and battery, if the window is minimized the requestAnimationFrame won't be sent by the browser, thus causing your animation to pause.
There's nothing you can do to change this browser behaviour.
You could link updating animations to a setInterval I guess, but browsers also throttle any window timeouts these days on a minimized window, again for cpu and battery saving reasons
You can render the stage at any time by calling;
renderer.render(stage);
You will have to call this in something like setInterval, rather than requestAnimationFrame in order for the animation to continue when the page is not active.
Related
There was a problem with audio playing in the exported instance of the game. The sound is played using the AudioStreamPlayer node. I export the game to html5 and run it either on a local server or on any service that executes html code. If during the game you minimize the browser, change the tab, make the game window NOT active, then all game processes are suspended, that is: the movement of all objects does not occur, all timers are suspended. BUT the music continues to play. I tried to handle a focus Notification , an input handle with a cursor to turn off the music, but this is not an option, because if you minimize the browser via alt + tab while on the tab with the game, then the focus does not go away and the input is still waiting (while as I said earlier, all other processes related to movement and the timer are suspended).
How stop this audio stream in this case?
thanks
I use Qt's wheelEvent to implement scrolling in a custom widget. Normally, this works fine.
However, when dragging the mouse and scrolling with the mouse wheel at the same time, it sometimes happens that rotating the mouse wheel by one step does not do anything at first (no wheelEvent is received). This might even randomly happen a few times successively. The next time the application does receive a wheelEvent, it comes with an accumulated event->angleDelta() of all previous events that were not reported separately. Apparently the events are buffered together in this case. Note that the wheelEvent may happen a long time after the initial mouse wheel rotation(s) in this case: it only happens once the wheel is rotated again.
This is an issue, since it means that my widget sometimes does not properly react to scrolling. Is there any way to avoid this kind of buffering and receive all wheel events immediately instead?
Notably this behavior is only well reproducible if at the same time dragging the mouse within the widget, which performs some non-trivial actions as a result. So I suspect it might happen if the event loop seems busy. But it certainly isn't busy enough to be unable to handle each wheelEvent. So I would like to disable this buffering.
I observe this on Linux with Qt 5.12.0. Any help is appreciated, thanks.
I am answering my own question here since I found the answer after writing it (but was unable to google it before).
The same problem has been reported here (with a somewhat non-descriptive title): Qt QOpenGLWidget wheelEvent strange behaviour
For me, setting Qt::AA_CompressHighFrequencyEvents (see https://doc.qt.io/qt-5/qt.html#ApplicationAttribute-enum) to false seems to have fixed the issue, as posted by #gatis paeglis as an answer to that question.
I have a wxApp implementation in which the wxFrame embeds a CEF browser.I have bindings from CEF framework to perform some Javascript bindings. The application shows up the initial screen and loads everything good. However, after a certain delay (not consistent), the app frame becomes non-responsive and does not handle any of the events. I have put up a wxTimer to figure out the amount of time it takes and it varies between 28 seconds to 60 seconds. This is where the timer events are also not called. Now when I press on the x or maximize icon on the window, all the pending events are sent and the application becomes active again.
Here are the options I tried:
Called wxTheApp->ProcessPendingEvents(); on the timer (runs every 1 second)
Tried and looked into onIdle method. This is also getting paused after a while
My guess is that the application main thread is paused for some reason and is not able to revert back unless any of the UI actions are triggering it.
Since there's no clear explanation in Chrome Extensions documentation, I came here for help.
I learned that background pages are basically invented to extend the extension's lifetime, and designed to hold values or keep the "engine" running in background so no one notices it. Because once you click on the extension's icon, you get what they call it, a "popup", and once you click outside the "popup" it disappears immediately and most important the extension "dies" (its lifetime ends).
So far we are good and everything is nice but: event pages are invented after that
and they are basically background pages that only work when they are called (to provide more memory space).
If that's the case, then wouldn't that be contradictory? What's the use of event pages if they only work when they're called?
Sometimes background pages only need to respond to events outside them (messages, web requests, button clicks, etc.)
In that case, an event page makes sense. It's not completely unloaded as if the extension is stopped - it defines its event handlers (what it wants to listen to) and then it's shut down until needed. Consider this to be "I'm going to sleep; don't wake me up unless A happens."
The difference with your example: closed popup ceases to exist completely, while Chrome remembers it needs to call a particular extension on particular events. If that event happens, the background page is started again an the event is fired in it.
This saves resources, but not always appropriate. Shutting down background page's context wipes its local state; it must be saved in various storage APIs instead of variables. If the local state is complex, it may not be worth the effort. Also, if your extension needs to react really fast or really often, suspend/resume may prove to be a performance hit.
All in all, event pages are not a complete replacement for background pages; that's why they are optional and not default. There are many things to consider when making an event page.
P.S. Regarding your "popup as most important part of the extension": this is exactly why it can't be the most important part in most cases. Usually, a background page is also used alongside a popup to keep event listeners and local state.
I'm trying to create a NinJump-like game using J2ME, and I've run into some problems with the animation.
My game built this way:
A thread is started as soon as the game is started. A while loop runs infinitely with a 20ms delay using thread.sleep().
The walls constantly go down - each time the main while loop runs, the walls are animated.
The ninja is animated using a TimerTask with a 30ms interval.
Each time the player jumps, the player sprite is hidden, and another sprite appears, which performs the jump using a TimerTask: 20ms interval, each time the task is executed the sprite advances the its next frame and it also moves (2px each time).
The problem is that when the player jumps, the wall animation suddenly gets slow. Also, the jumping animation is not smooth, and I just can't seem to be able to fix it using different animation time intervals.
I guess there's something wrong in the way I implemented it. How can the problems I mentioned above?
Don't use TimerTask to animate the sprites, do it on the main game loop.