November 2017
Beginner to intermediate
298 pages
6h 47m
English
The elements you're dealing with are raindrops. Before we update or animate a single raindrop, we produce them. We're building out a so called object literal module called rain (it's an object literal) that knows how to produce raindrops and that keeps the individual drops save in an array called items. It will look like so:
var rain = { items: [], maxDrops: 200, getDrop: function() { var obj = {}; obj.xStart = Math.floor(Math.random() * canvas.width); obj.yStart = Math.floor(Math.random() * -canvas.height); obj.x = null; obj.y = null; obj.speed = Math.round(Math.random() * 2) + 5; return obj; }, updateDrop: // see below }
The rain object consists of this as yet empty array items that will hold all the raindrop objects ...
Read now
Unlock full access