actionscript 3 - Why EnterFrame occurs before refreshing the screen in Flash -


suppose have animation in flash 1 fps, each frame has script runs 100 ms. far know, animation in flash works follows:

0ms: begin executing frame 1's frame script 100ms: finish executing frame 1's frame script 1000ms: begin rendering frame 1's content , frame-script output 1050ms: finish rendering frame 1's content , frame-script output  1051ms: begin executing frame 2's frame script 1151ms: finish executing frame 2's frame script 2000ms: begin rendering frame 2's content , frame-script output 2050ms: finish rendering frame 2's content , frame-script output  2051ms: begin executing frame 3's frame script 2151ms: finish executing frame 3's frame script 3000ms: begin rendering frame 3's content , frame-script output 3050ms: finish rendering frame 3's content , frame-script output ... 

this workflow logical, frame script being executed while waiting next screen update. if script takes long 1000ms execute, rendering not delayed , still 1fps.

however! when programming animation within as3, people use enter_frame event, occurs just before next screen update. then, if have instructions take 1000ms execute, workflow follows:

0ms: nothing (waste time!) 1000ms: begin executing instructions in enter_frame 2000ms: finish executing instructions in enter_frame 2001ms: begin rendering frame 1's content , enter_frame output 2051ms: finish rendering frame 1's content , enter_frame output  2051ms: nothing (waste time!), have wait 1000ms last rendering current 3000ms: begin executing instructions in enter_frame (1000ms after last rendering) 4000ms: finish executing instructions in enter_frame 4001ms: begin rendering frame 2's content , enter_frame output 4051ms: finish rendering frame 2's content , enter_frame output  4051ms: nothing (waste time!), have wait 1000ms last rendering current 5000ms: begin executing instructions in enter_frame (1000ms after last rendering) 6000ms: finish executing instructions in enter_frame 6001ms: begin rendering frame 2's content , enter_frame output 6051ms: finish rendering frame 2's content , enter_frame output ... 

as result have 0.5 fps instead of 1 fps! delays come because enter_frame occur right before rendering scene. me, logical if enter_frame occurred right after rendering scene, prepare rendering @ next frame.

this toy example, , in real world rendering not occur @ perfect schedule, logic same. when having 15 ms of code execute each frame (perfectly normal situation), 60 fps turn 30 fps...

... or not? there flaw in saying?

enter frame beginning of lifecycle.

enter-frame

display object lifecycle:

  1. event of event type event.enter_frame dispatched
  2. constructor code of children display objects executed
  3. event of event type event.added dispatched children display objects
  4. event of event type event.added_to_stage dispatched children display objects
  5. event of event type event.frame_constructed dispatched
  6. movieclip frame actions executed
  7. frame actions of children movieclips executed
  8. event of event type event.exit_frame dispatched
  9. event of event type event.render dispatched
  10. event of event type event.removed dispatched children display objects
  11. event of event type event.removed_from_stage dispatched children display objects

what describe referred elastic racetrack, heavy code execution can delay frame rendering.

elastic-racetrack

frame-rate


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -