为什么在刷新Flash中的屏幕之前会出现EnterFrame

Geo*_*kov 1 flash actionscript-3 enterframeevent

假设我们在Flash中有1 fps的动画,其中每个帧都有一个运行100 ms的脚本.据我所知,Flash中的动画工作原理如下:

0ms: Begin executing Frame 1's frame script
100ms: Finish executing Frame 1's frame script
1000ms: Begin rendering Frame 1's content and frame-script output
1050ms: Finish rendering Frame 1's content and 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 and frame-script output
2050ms: Finish rendering Frame 2's content and 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 and frame-script output
3050ms: Finish rendering Frame 3's content and frame-script output
...
Run Code Online (Sandbox Code Playgroud)

此工作流程是合乎逻辑的,因为在等待下一次屏幕更新时正在执行框架脚本.即使脚本执行时间长达1000毫秒,渲染也不会延迟,它仍然是1fps.

然而!在AS3中编程动画时,人们经常使用ENTER_FRAME事件,该事件发生在下一次屏幕更新之前.然后,如果我们有执行1000毫秒的指令,则工作流程如下:

0ms: do nothing (waste time!)
1000ms: begin executing instructions in ENTER_FRAME
2000ms: finish executing instructions in ENTER_FRAME
2001ms: Begin rendering Frame 1's content and ENTER_FRAME output
2051ms: Finish rendering Frame 1's content and ENTER_FRAME output

2051ms: do nothing (waste time!), as we have to wait 1000ms from last rendering to 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 and ENTER_FRAME output
4051ms: Finish rendering Frame 2's content and ENTER_FRAME output

4051ms: do nothing (waste time!), as we have to wait 1000ms from last rendering to 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 and ENTER_FRAME output
6051ms: Finish rendering Frame 2's content and ENTER_FRAME output
...
Run Code Online (Sandbox Code Playgroud)

结果我们有0.5 fps而不是1 fps!延迟是因为ENTER_FRAME 渲染场景之前发生.对我来说,如果渲染场景后立即发生ENTER_FRAME ,为下一帧的渲染做准备将是合乎逻辑的.

这是一个玩具示例,在现实世界中,渲染不会在完美的时间表上发生,但逻辑是相同的.当有15毫秒的代码执行每一帧(完全正常的情况)时,60 fps会变成30 fps ......

... 或不?我所说的是否存在缺陷?

Jas*_*ges 5

输入框架是生命周期的开始.

输入框

显示对象生命周期:

  1. Event.ENTER_FRAME调度事件类型的事件
  2. 执行子显示对象的构造函数代码
  3. Event.ADDED从子显示对象调度的事件类型的事件
  4. Event.ADDED_TO_STAGE从子显示对象调度的事件类型的事件
  5. Event.FRAME_CONSTRUCTED调度事件类型的事件
  6. 执行MovieClip帧动作
  7. 执行子MovieClip的帧动作
  8. Event.EXIT_FRAME调度事件类型的事件
  9. Event.RENDER调度事件类型的事件
  10. Event.REMOVED从子显示对象调度的事件类型的事件
  11. Event.REMOVED_FROM_STAGE从子显示对象调度的事件类型的事件

你所描述的通常被称为弹性赛道,其中繁重的代码执行可以延迟帧渲染.

弹性跑道

帧速率