HTML and CSS Reference
In-Depth Information
Creating an Animation Frame Counter
We can simulate the ship's exhaust firing by rapidly flipping between the first two tiles (or
cells) on our tile sheet. To do this, we set up a counter variable, which is how we track the tile
we want to paint to the canvas. We will use 0 for the first cell and 1 for the second cell.
We will create a simple integer to count which frame we are displaying on our tile sheet:
var
var counter = 0 ;
Inside drawScreen() ,wewillincrementthisvalueby 1 oneachframe.Becausewehaveonly
two frames, we will need to set it back to 0 when it is greater than 1 :
counter ++ ;
iif ( counter > 1 ) {
counter = 0 ;
}
Or use the following nice shortcut. This is a “bit-wise” operation that will simplify code, but
we do not have the space to go into the full range of bit-wise operations in this text.
counter ^= 1 ;
Search WWH ::




Custom Search