I am creating html game where i generate platforms by manually adding them into the array platforms, therefore I created a function that will adding objects into that array. But it throws an error:
canvas.bundle.js:230 Uncaught TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))
let generation = ( object, array, image, y ) => {
array = [... array, new object({
x: LastPos, y, image
})]
LastPos = image.width + Math.floor(Math.random() * 1000)
}
generation(Platform,platforms,platformImage,470)
the function execution will be in the loop
P.S object to be generating is the class:
class Platform {
constructor({x, y, image}) {
this.position = {
x, y
}
this.image = image
this.width = image.width
this.heigth = image.height
}
draw() {
c.drawImage(this.image, this.position.x, this.position.y)
}
}