Prev | Current Page 739 | Next

Frank Zammetti

"Practical DWR 2 Projects"

src;
dwr.util.byId("tilePlayer_" +
CHAPTER 8 n DWR FOR FUN AND PROFIT (A DWR GAME!) 438
inMemoria.playerFlippedTile2).src =
inMemoria.explosionImages[inMemoria.playerExplosionFrame].src;
} // End cyclePlayerExplosion().
The way an explosion here works is simple. There are five frames of animation. A complete
explosion animation cycle is displaying all of them in ascending order, and then
displaying all of them in descending order. This gives the illusion of expanding hot gas (i.e., an
explosion!), which then contracts and dissipates. Each frame is 1/10 of a second in length, or
100 milliseconds. So, another interval is set up with that period that fires this method each
iteration.
So first, this method looks at the playerExplosionDir field. When it??™s true, we??™re incrementing
the frame number each time. So, all we need to do each time is check to see what
frame we??™re on. If we??™re on frame 4 (it??™s zero-based, so frame 4 is the fifth frame), we set
playerExplosionDir to false, which reverses things, meaning we??™ll begin to decrement the
frame number.
Now, when playerExplosionDir is false, the logic is similar. Decrement the frame number,
and then check it to see whether we??™re at less than zero.


Pages:
727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751