As3 gotoAndStop 在一个输入帧中进行多个调用

发布于 2024-10-22 12:14:07 字数 668 浏览 1 评论 0原文

我正在尝试制作用于 DisplayObjects 旋转的精灵表,并且 gotoAndStop() 调用似乎不起作用。

这是发生的情况的示例:

function createRotationalSpriteSheet ( displayObject : DisplayObject )
{
    findMaxTileDimensions( displayObject );
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call does not work.
}

function findMaxTileDimensions ( displayObject : DisplayObject )
{
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call works fine
}

对于不起作用的 gotoAndStop 调用,标签和帧编号已更新,但是当我尝试使用 BitmapData.draw 绘制 DisplayObject 时,帧仍然卡在被告知的最后一帧上转到 findMaxTileDimensions 函数。

发生这种情况是因为我在一个输入帧中多次调用 gotoAndStop 函数吗?发生这种情况是因为我在同一输入框架中从两个不同的函数调用 gotoAndStop 吗?

I am trying to make sprite sheets for rotation of DisplayObjects, and it seems that the gotoAndStop() calls are not working.

Here's an example of what's going on:

function createRotationalSpriteSheet ( displayObject : DisplayObject )
{
    findMaxTileDimensions( displayObject );
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call does not work.
}

function findMaxTileDimensions ( displayObject : DisplayObject )
{
    MovieClip( displayObject ).gotoAndStop( 1 ); // this call works fine
}

For the gotoAndStop call that doesn't work, the label and frame number are updated but when I try to draw the DisplayObject with BitmapData.draw, the frame is still stuck on the last frame it was told to go to in the findMaxTileDimensions function.

Is this happening because I am calling the gotoAndStop function to many times in one enter frame? Is it happening because I'm calling gotoAndStop from two different functions in the same enter frame?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

才能让你更想念 2024-10-29 12:14:07

这里似乎发生了一些事情。您正在使用 gotoAndStop(),但只有在其他所有事情发生之后才会更新图像。来自文档 - http://help .adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndStop() - “将播放头移至影片剪辑的指定帧并停止在那里。这发生在帧中的所有剩余操作完成执行之后。”因此,如果您希望它起作用,那么您需要在多个帧上执行此操作。

其次,您提到这是为了整理 DisplayObjects 的旋转以将它们绘制为 BitmapData 的 - MovieClip 中有动画吗?或者是MovieClip旋转的动画。如果是后者,那么通过代码设置旋转并绘制不同的角度将像您尝试做的那样工作(即全部在一帧中)

另请参阅 bit101 的 SWFSheet: bit-101.com/blog/?s=swfsheet" rel="nofollow">http://www.bit-101.com/blog/?s=swfsheet。它用于拍摄动画并为其导出 PNG 精灵。那里可能有代码,我不确定。在任何情况下,您都可以保存动画,然后将其嵌入/加载

A few things seem to be going on here. You're using gotoAndStop(), but that won't update the images until after everything else has happened. From the docs - http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/MovieClip.html#gotoAndStop() - "Brings the playhead to the specified frame of the movie clip and stops it there. This happens after all remaining actions in the frame have finished executing." So if you want this to work, then you'll need to do it over multiple frames.

Secondly, you mention that this is to sort out rotation of DisplayObjects to draw them as BitmapData's - is there animation in the MovieClip? Or is the animation that of the MovieClip rotating. If it's the latter, then setting the rotation through code and drawing the different angles will work as you're trying to do (i.e. all in one frame)

Also check out SWFSheet by bit101: http://www.bit-101.com/blog/?s=swfsheet. It's made to take an animation and export PNG sprites for it. There might be the code there, I'm not sure. In any case, you can save your anim, then embed/load it in

初心 2024-10-29 12:14:07

这听起来可能是 AIR 中的已知错误(假设它只发生在 AIR 中):
https://bugbase.adobe.com/index.cfm?event=bug& ;id=3340012

该错误报告提到了一个 hacktastic 解决方法,我刚刚验证了它确实有效:在运行之前将您的 MovieClip 添加到舞台中。完成后您可以将其删除。

或者,您可以实例化 MovieClip 两次(一次获取尺寸,然后一次创建 BitmapDatas),或者在 MovieClip 的开头添加一个空的虚拟帧并忽略第一帧。

This sounds like it might be this known bug in AIR (assuming it only happens in AIR):
https://bugbase.adobe.com/index.cfm?event=bug&id=3340012

The bug report mentions a hacktastic workaround, which I just verified does work: add your MovieClip to the stage before you run through it. You can remove it when you're done.

Alternately, you could instantiate the MovieClip twice (once to get the dimensions, then once to create the BitmapDatas), or add an empty dummy frame at the start of your MovieClip and ignore that first frame.

埖埖迣鎅 2024-10-29 12:14:07

这里发生了两件事。主要问题是 gotoAndStop 是从 1 开始的,而不是从 0 开始的。 gotoAndStop(0) 不会生成错误,因为它需要一个对象(因此它可以接受标签或帧号)。

由于遗留原因,gotoAndStop 是基于 1 的 - 即与 Flash IDE 中旧的处理方式相关。

如果将其更改为基于 1 的系统仍然不起作用,您将需要 addframescript (基于 0 )请在此处查看我的答案

AS3 - gotoAndStop 立即执行

Two things are happening here. The main issue is that gotoAndStop is 1-based, not 0-based. gotoAndStop(0) won't generate an error though because it is expecting an object (so it can take a label or frame number).

gotoAndStop is 1-based for legacy reasons - i.e. tied to the old way of doing things in the flash IDE.

If changing this to a 1-based system still doesn't work, you will need to you addframescript (which is 0-based) see my answer here

AS3 - gotoAndStop with immediate action

辞别 2024-10-29 12:14:07

作为一个更好的用例,我认为最好使用位图,然后将其缓存在某些数据结构中:
读这个:
http://www.8bitrocket.com/2010/3/3/Tutorial-AS3-How-to-Blit-an-animation-from-a-tile-sheet-embedded-at-编译时/

另外,也许我对这个问题不是 100% 清楚,但为什么需要使用 Enterframe 来创建精灵表?

您可以仅旋转位图,然后将其捕获为位图数据,或者简单地对位图数据使用矩阵变换
http://www.8bitrocket.com/2010/05/01/tutorial-exploring-the-as3-bitmap-class-lesson-3-scale-from-the-center-with- a-矩阵/

As a better use case, I think it would be better to use bitmap and then cache it in some data structure:
read this:
http://www.8bitrocket.com/2010/3/3/Tutorial-AS3-How-to-Blit-an-animation-from-a-tile-sheet-embedded-at-compile-time/

also, maybe i'm not 100% clear on the question but why do you need to use enterframe to create a sprite sheet?

you can just rotate the bitmap then capture it as a bitmapData, or simply use a matrix transformation on the bitmap data
http://www.8bitrocket.com/2010/05/01/tutorial-exploring-the-as3-bitmap-class-lesson-3-scale-from-the-center-with-a-matrix/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文