Supercharged JavaScript Graphics by Cecco Raffaele

Supercharged JavaScript Graphics by Cecco Raffaele

Author:Cecco, Raffaele [Raffaele Cecco]
Language: eng
Format: epub, mobi
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9781449313074
Publisher: O'Reilly Media, Inc.
Published: 2011-07-10T16:00:00+00:00


Figure 6-13. Naively animating moving squares in Canvas may not give the result you expect

Remember, Canvas is a low-level and immediate mode system: each loop iteration simply draws another rectangle on the screen, on top of the previous iteration’s rectangle. This results in a big smeared shape, not a moving rectangle. We need to do a bit more work to create an animated square that moves across the page:

Store an initial position for the square (x, y).

Clear the canvas.

Update the square’s position by changing x, y, or both.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.