Hi list.

I was trying to create an animated sprite with several frames, and have it
move around the screen, and I encountered some difficulties.
I managed to overcome them (kinda), so I thought I'd share my results, or
get some even better solutions (in case it turns out I was doing it
completely wrong and doing it right would avoid the errors alltogether...).

Creating a sprite was easy, so was placing it on scene with <place id...
ect>. To have it move, I was trying to <place /> it in another position, and
here's my
problem 1:
<place />ing the object again would reset the sprite to first frame-
effectively making it non-animated.
Upon examining the generated low-level code, it turned out <place />ing an
object on a previously used depth, inserts an explicit <RemoveObject2 />
before the <PlaceObject2 replace="0".../> (It has replace="0" because after
deleting the last one, there's no longer anything to replace)

To support an animated sprite it shouldn't do that (I think), and the
following PlaceObject2 should have 'replace="1"' tag.

Partial Solution:
It's simple enough to fix in low-level code.

For swfml simple, I made an xslt template, equivalent to simple dialect,
that gives some support to replace argument.

To modify the template, remove this portion:
<xsl:variable name="replace">
        <xsl:choose>
            <xsl:when test="preceding-sibling::[EMAIL PROTECTED] or
../preceding-sibling::frame/[EMAIL PROTECTED]">1</xsl:when>
            <xsl:otherwise>0</xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:if test="$replace = '1'">
        <RemoveObject2 depth="[EMAIL PROTECTED]"/>
    </xsl:if>
    <PlaceObject2 replace="0" morph="{$replace}" depth="{$depth}"
objectID="{$id}">



and put this code in it's place:


  <xsl:variable name="morph">
    <xsl:choose>
      <xsl:when test="preceding-sibling::[EMAIL PROTECTED] or
../preceding-sibling::frame/[EMAIL PROTECTED]">1</xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

  <xsl:variable name="replace">
    <xsl:choose>
      <xsl:when test="@replace"><xsl:value-of select="@replace"/></xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>

    <xsl:if test="$morph = '1' and $replace = '0' ">
        <RemoveObject2 depth="[EMAIL PROTECTED]"/>
    </xsl:if>

    <PlaceObject2 replace="{$replace}" morph="{$morph}" depth="{$depth}"
objectID="{$id}">

Then, when an animated sprite is desired include 'replace="1"' in list of
<place />'s arguments, and compile with
swfmill xslt templatename input output


It could probably use some checks to see if ObjectID and name match between
the last object and the new, but I'm not sure how to do that.

As you see, I kept "morph" argument, but what is it actually? It connects to
my other problem with animated sprites.

Problem 2:
When trying to construct an animated sprite in low-level code, you need to
use a special trick, otherwise the first frame shows at first, but refuses
to appear on subsequent loop iterations.

eg. this code doesn't work:
<DefineSprite objectID="10" frames="6">
        <tags>
          <PlaceObject2 replace="0" depth="5" objectID="1"/>
          <ShowFrame/>  <ShowFrame/>  <ShowFrame/>
          <RemoveObject2 depth="5" />
          <PlaceObject2 replace="0" depth="5" objectID="2"/>
          <ShowFrame/> <ShowFrame/>  <ShowFrame/>
          <End />
          </tags>
</DefineSprite>

The tricks that fix the code include:
adding <RemoveObject2 depth="5" /> after the last <ShowFrame/> or before the
first <PlaceObject2...
changing depth in the second PlaceObject2 to a different value
adding 'morph="1"' attribute to second PlaceObject2

The first "trick" is very natural- it would work if the animations were
simply chained upon another, without stage clear, removeObject2 clears the
stage by hand.

The second is slightly weird- at first I thought the objects are retained
during the jump from last frame back to first, but it's not so, as the
object placed on different depth disappears as expected, and then reappears
in the next iteration.
But apparently some data is kept- enough to prevent the first PlaceObject2
from working correctly...

The third "trick" has me very confused.
So some data is kept, but including 'morph="1"' makes it clear? Or lets the
PlaceObject2 override it? Or what?
And it only works on the last frames of animation. Is this a bug? Or maybe
the fact that it works at all is a bug?

What is "morph" actually?
I seem to recall one place mentioned it's used for in-between stages in some
interpolated thingies...
maybe it only works for my animated sprites due to some bug/coincidence. Or
but maybe it was some other "morph".
Or maybe I'm doing something wrong?

Thank you for your attention.

PS.
If I'm doing it right, included are the following files:
nLoops.swf - showing the problems I encountered and the fixed versions.
Notice how the first number skips "1" every time (that's example of problem
2, the next 3 are examples of workarounds), next the moving numbers
underneath are examples of problem #1. The first one with replace="0"
doesn't animate, the one with replace="1" animates.
nlib.swf - library of images for the previous file

Attachment: nLoops.swf
Description: application/shockwave-flash

Attachment: nlib.swf
Description: application/shockwave-flash

_______________________________________________
swfmill mailing list
[email protected]
http://osflash.org/mailman/listinfo/swfmill_osflash.org

Reply via email to