Because of the constant attack by the wiki spam bots, accounts that are created and not used will be deleted. If you are a legitimate user, and your IP was blocked, please contact any active administrator - look at Special:RecentChanges and see who is busy fighting spam.

Sprite

From SWFTools
Jump to: navigation, search

Sprite, in the sc language compiled by swfc, is the way to nest a flash application inside another application.

Let's try to see why we need a sprite. As an example, let's try to write a flash application with two circles. One of them will be a yellow circle, fixed in the middle of the flash. The other will be a blue circle that will move along the main diagonal, passing over the circle, then it will move back to its initial position.

How can we do it? The script, below, does not work:

.flash bbox=400x400 fps=50 background=black
  .circle yellowcircle r=30 color=yellow fill
  .circle bluecircle r=30 color=blue fill

  .put yellowcircle x=200 y=200 pin=center

  .frame 1
  .put bluecircle x=30 y=30 pin=center

  .frame 101
  .move bluecircle x=370 y=370

  .frame 201
  .move bluecircle x=30 y=30
.end

The problem is that there is no (practical) way to have the blue circle move sometimes above, and sometimes below, the yellow circle. However, let's try to split this application in three: one upper application moves the bluecircle along the diagonal, and above the yellow circle, the middle application is just the yellow circle, and the lower application move the blue circle along the diagonal, but behind the yellow circle. This can be easily done with sprites:

.flash bbox=400x400 fps=50 background=black
  .circle yellowcircle r=30 color=yellow fill
  .circle bluecircle r=30 color=blue fill

  .sprite above
     .frame 1
     .put bluecircle x=30 y=30 pin=center

     .frame 101
     .move bluecircle x=370 y=370

     .frame 102
     .del bluecircle

     .frame 201
  .end

  .sprite below
     .frame 101
     .put bluecircle x=370 y=370 pin=center

     .frame 201
     .move bluecircle x=30 y=30
  .end

  .put below
  .put yellowcircle x=200 y=200 pin=center
  .put above
.end