As3 gotoAndStop multiple calls in one enter frame
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 开发者_JAVA百科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?
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
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.
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
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/
精彩评论