AS3的Flash动画在苹果VS视窗视窗、苹果、动画、Flash

2023-09-08 15:34:25 作者:兜兜里没有棒棒糖i

我工作的一个简短的动画故事,其中有一个擦洗时间表和章节标题。我用TimelineMax测序它。在大多数情况下,这是工作的罚款。我看到一些奇怪的行为弹出,但:精灵消失,功能停止响应用户输入时,精灵的接缝变得透明 - 所有的小问题,而是pretty的难以明确,因为它们发生在仅适用于Mac。

I am working on a short animated story, which has a scrubbable timeline and chapter headings. I used TimelineMax for sequencing it. For the most part, it is working fine. I am seeing some strange behavior that pop up, though: sprites disappear, functions stop responding to user input, seams of the sprites become transparent -- all small issues but pretty hard to nail down because they happen in Mac only.

所以,我想知道什么是错的闪存,以及为什么它的行为不端在Mac上?

So I am wondering what is wrong with Flash, and why it misbehaves on a Mac?

推荐答案

我经常工作在Windows上的工作,然后我的Mac在家里一样的项目。我也看到了Mac上的一些差异相比Windows。我发现不同的Flash播放器版本为Mac一般比Windows播放慢,我见过没有发生在Windows在Mac上的一些奇怪的行为。

I frequently work on the same projects on Windows at work and then my Mac at home. I also see some difference on the Mac compared to Windows. I find that various Flash Player versions for the Mac are generally slower than the Windows players, and I've seen some odd behavior on the Mac that is not happening on Windows.

在大多数情况下,我已经缩小下来到AS3的垃圾回收。垃圾收集发生在玩家确定的对象不再有在电影中的引用,所以它会删除该对象以释放内存。比方说,你有一个类的方法是这样的:

In most cases I've narrowed this down to AS3's garbage collection. Garbage collection happens when the player determines that an object no longer has a reference in the movie, so it removes that object to free up memory. Let's say you have a class method like this:

function myTweenFunction():void {
    var myTween:Tween = new Tween(myDisplayObject, 'x', Strong.easeInOut, 0, 500, 10, true);
    myTween.addEventListener(TweenEvent.MOTION_FINISH, onMyTweenDone);
}

的方法,将上述补间超过10秒的过程myDisplayObject的x值从0到500。当该补间完成,就应激发的onMyTweenDone方法(未示出)。然而,myTween在里面myTweenFunction创建的,因此它只存在于myTweenFunction范围。当myTweenFunction完成后,myTween对象不再由在电影的任何对象所引用,使其成为用于垃圾收集的候选。你会开始看到补间,但在某些时候才到达500和终点事件将不会触发它就会停止。这意味着,myTween已被破坏。要解决这个问题,myTween需要是类的成员,或者只是需要有一个参考的一类函数外。

The method above will tween myDisplayObject's x value from 0 to 500 over the course of 10 seconds. When that tween is done, it should fire the onMyTweenDone method (not shown). However, myTween was created inside myTweenFunction so it only exists in the scope of myTweenFunction. When myTweenFunction is done, the myTween object is no longer referenced by any object in the movie so it becomes a candidate for garbage collection. You will start to see the tween, but at some point it will stop before it gets to 500 and the finish event will not fire. This means that myTween has been destroyed. To fix this problem, myTween needs to be a member of the class, or just needs to have a reference outside of a class function.

再回到到Mac与Windows的问题,我看到在Mac上运行时创建的对象的垃圾回收是比在Windows更加明显。垃圾收集发生在Windows的Flash Player,但在此之前发生垃圾收集,因为Windows的Flash播放器具有更好的性能补间和其他事件可能会完成。如果Mac的Flash播放器会更慢(即相同的补间可能需要更长的时间),那么垃圾收集可能发生补间完成之前。垃圾回收,不会发生帧一帧像的动画;这是一个后台进程,可以发生在任何时间,或根本没有,如果有足够的内存为Flash播放器。你的Windows机器可能有一堆的RAM和电影可以播放罚款,而不需要进行垃圾回收,所以myTween也许永远不会消失。如果您的Mac有更少的内存,或者如果你有大量的应用程序同时打开和Flash Player的内存分配是有限的,那么Flash Player将更加频繁地执行垃圾收集。

Getting back to the Mac vs. Windows issues, I see that garbage collection on runtime-created objects on the Mac is more apparent than on Windows. Garbage collection happens in the Windows Flash Player, but the tweens and other events may be finishing before garbage collection occurs since the Windows Flash Player has better performance. If the Mac Flash Player is slower (ie. the same tween might take longer), then the garbage collection might happen before the tween is done. Garbage collection does not occur frame-by-frame like an animation; it's a background process that can happen at any time, or not at all if there's enough memory for the Flash Player. Your windows machine might have a pile of RAM and the movie can play fine without the need for garbage collection, so myTween might never go away. If your Mac has less memory, or if you have a ton of apps open at once and the Flash Player memory allotment is limited, then the Flash Player will perform garbage collection more frequently.

我也用TimelineMax,而且也由默认打开的自动垃圾收集功能。尝试关闭的关闭,测试在Mac上。

I've also used TimelineMax, and there's an auto garbage collection feature that is turned on by default. Try turning that off and test on the Mac.

最后,你应该设计自己的项目,因此收集到的假设,一个用户可能有非常有限的内存,让你的对象需要创建,引用和垃圾。

Ultimately, you should design your project with the assumption that a user may have very limited memory, so your objects need to be created, referenced, and garbage collected accordingly.