By using counters and simple mathematical calculations, we can indeed describe all sorts of movements a sprite of arbitrary complexity may perform over time. Notwithstanding, animation is not limited to only moving the sprites around; quite often actually, we will be looking into implementing certain effects or more complex kinds of motion.
A typical case is that of adding trailing effects to an animation. If done wisely, trailing effects will make our animations a lot more interesting and organic. We can easily achieve such effects if we merge the current frame with the previous ones rather than replacing them. Consider the following code wherein we set the clearOnRefresh
variable to false
(to instruct UserView
to merge every frame with the previous ones) and use a semitransparent rectangle to dampen the previous contents before actually drawing the new content.
( // rotating windmill trailing effect var window, userView, windmill, speed =...