javascript - How can I allow Easeljs Tickers to remain active when a user switches tabs -


i making game using createjs , have problem game pausing automatically once switch tabs. have researched on topic , believe have found out isn't createjs pausing tickers browsers themselves. has page visibility api knows when document hidden or visible , once hidden, believe slows down raf or setintervals of document makes seem paused. provides cpu , battery don't burn out.

i need game keep running in background if user switches tabs. best way can this? want mention using easeljs tickers if matters.

please correct me if wrong said. still beginner , correcting me, able understand real problem. thank time.

the behaviour describing expected, browser throttle javascript execution 1 fps.

the usual approach around make sure application/animations not tied specific fps. example, here sample shape moves across screen: http://jsfiddle.net/lannymcnie/4neobe00/2/

  • it takes 5 seconds go left right
  • a count shows how many times resets

if add amount sprite (such blue shape), updated 1 time per second when browser frame closed. used 1.66 because closely matched speed of other sprite.

lockedshape.x = (lockedshape.x + 1.66); // moves amount per tick 

however ticker provides delta in tick event, around 1 when have reliable framerate, provide multiplier can use determine how long frame takes. in sample, index incremented 1 x event.delta:

index += event.delta;  

then position determined based on index:

shape.x = (index/10)%500; // divide 10 slow down, modulus 500 make loop 

we can determine how many times item has "looped" because know if divide index width, give number of loops:

text.text = (index/10/500 |0).tostring(); // rough position divided 500, rounded. 

so using approach, can make rest of content run @ consistent speed, since know how time has elapsed since last tick. here official tutorial (which has sample same thing, in head when made own example).

note tweenjs uses time-based tweens, , can set framerates on movieclips , sprites in easeljs, uses approach.

hope helps.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -