跳帧闪存闪存

2023-09-09 21:38:10 作者:其实都很庸俗

有没有一种方法,以使本机闪存跳帧?

Is there a way to natively enable frame skipping on Flash?

当你开发一个游戏,你开发的动画相匹配的游戏的速度,并做到这一点的目标帧速率(通常为24-40fps为Flash)。但如果用户的计算机是太慢,并且不能保持目标帧速率,Flash将自动降低帧率,使得应用程序播放慢慢

When you develop a game, you develop animations to match the pace of the gameplay, and do it on a target frame-rate (usually 24-40fps for Flash). But if the user's computer is too slow, and cannot maintain the target frame-rate, Flash will automatically lower the fps, making the application play slowly.

如果您使用的是基于时间的逻辑,基于帧渲染不会在基于时间的逻辑一致,事情会奇怪,以后还有很多其他的情况来解决。

If you use a time based logic, the frame based rendering will not match the time based logic, and things will be weird and there'll be a lot of corner cases to work around.

我知道通过事实,有些游戏使用这种跳帧的逻辑,如PopCap的祖玛闪电战的。难道他们实现跳跃在自己的框架?

I know by fact that some games use this sort of frame skipping logic, such as Popcap's Zuma Blitz. Are they implementing the frame skipping on their own?

我没有能力实现这个所以在项目后期,除非我能以某种方式重新实现MovieClip类并使其易于帧skipabble。此外,将控制动画,在你自己的(改写闪存本土影片剪辑控制)太大的开销不是开销?

I cannot afford to implement this so late in the project unless I can somehow reimplement the MovieClip class and make it easily frame skipabble. Also, wouldn't the overhead of controlling the animations on your own (overwriting Flash native MovieClip control) be too much of an overhead?

推荐答案

好吧,我知道你是不是在找下面的解决方案,这是行不通的,因为所有的帧仍然会发挥:

Okay, I realize that you're not looking for the following 'solution', which won't work, as all frames will still be played:

stage.frameRate = new_frame_rate;

唯一的解决办法是只跳过你的enterFrame回调帧:

The only solution is to just skip frames in your enterFrame callback:

// Defined elsewhere.
var current_frame:Number = 0;
var frame_skip_factor:uint; // Skip one frame every 'x' frames.
var is_frame_skip_active:Boolean;

function on_enter_frame(event:Event):void
{
   if ( is_frame_skip_active && current_frame++ % frame_skip_factor == 0) { return; }

   // Game logic/rendering code...
}

(假设每最佳实践,你集中游戏逻辑/动画在一个单一的回调),但可能present竞争条件/并发症时,任何异步回调运行。

(assuming, per best practices, you've centralized game logic/animation in a single callback), but that may present race conditions/complications when any asynchronous callbacks are run.

有没有办法实际跳过在运行时级别帧;这是AVM的合同的一部分 - 没有帧被跳过,所有code为跑,不管是什么。如果性能是一个问题,你可以尝试异步code执行。有几个方法可以做到这一点:

There is no way to actually skip frames at the runtime level; this is part of the contract of the AVM - no frames are skipped, all code is ran, no matter what. If performance is an issue, you might try asynchronous code execution. There are a couple of ways to do it:

1)卸载一些计算来的Pixel Bender,以便它可以被异步地处理和/或并联(http://www.adobe.com/devnet/flex/articles/flashbuilder4_pixelbender.html)

1) Offload some computing to Pixel Bender, so that it can be processed asynchronously and/or in parallel (http://www.adobe.com/devnet/flex/articles/flashbuilder4_pixelbender.html)

2)S $ P $垫了长时间的操作在多个帧(的执行需要一个状态保存和状态恢复,一拉备忘录模式)。详细信息(和一个伟大的读)在这里: http://www.senocular.com/flash/tutorials / asyncoperations /

2) Spread out the execution of lengthy operations over multiple frames (requires a state save and state restore, a la memento pattern). Details (and a great read) here: http://www.senocular.com/flash/tutorials/asyncoperations/

在任何情况下,我会(首先)建议明确识别与像在Flash Builder探查或Stats类(Doob先生)工具的性能瓶颈。

In any case, I'd (first and foremost) recommend definitively identifying the performance bottleneck with a tool like the Flash Builder Profiler or the Stats class (Mr. Doob).

位图传输可能是解决方案(创建一个瓷砖动画的每一帧spritesheet)为好。但在任何情况下,我认为你需要做的是子类影片剪辑并重写播放(),停止(),和的gotoAndPlay()方法。你的类应该是这个样子:

Blitting might be the solution (create a spritesheet with a tile for each frame of the animation) as well. But in any case, I think what you'll need to do is subclass MovieClip and override the play(), stop(), and gotoAndPlay() methods. Your class should look something like this:

public class MyMovieClip extends MovieClip
{
   override public function play():void
   {
      addFrameSkipListener();

      super.play();
   }

   override public function gotoAndPlay(frame:Object, scene:String = null):void
   {
      addFrameSkipListener();

      super.gotoAndPlay(frame, scene);
   }

   // ....
}

凡跳帧听者将跳过帧根据当前帧速率或帧时间,如果需要的话。当然,你还需要删除frameSkipListener当动画已经到头了。

Where the frame skip listener will skip frames according to the current frame rate or frame time, if necessary. Naturally, you'll also need to remove the frameSkipListener when the animation has reached an end.

虽然影片剪辑覆盖的解决方案可能会做你想要在纸上的东西,如果你有很多的对象,这实际上降低性能的额外ENTER_FRAME监听器会增加一些开销。

While the MovieClip override solution might do what you want on paper, if you have a lot of objects, this might actually degrade performance as the additional ENTER_FRAME listeners will add some overhead.