Help redering array

why would this not be working on canvas

Blockquote

class Projectile{
constuctor({position,velocity}){
this.position = position
this.velocity = velocity

    this.radius = 3
}

draw(){
    c.beginPath()
    c.arc(this.position.x, this.position.y, this.radius,0,Math.PI * 2)
    c.fillStyle = 'yellow'
    c.fill()
    c.closePath()
}

update(){
    this.draw()
    this.position.x += this.velocity.x
    this.position.y += this.velocity.y
}

}

//player object
const player = new Player()

//porjectiles array
const projectiles = [
new Projectile({
position: {
x: 300,
y: 300
},
velocity: {
x: 5,
y: 0
}
})
]

Blockquote

projectiles.forEach(projectile => {
    projectile.update()
});

main.js:63 Uncaught TypeError: Cannot read properties of undefined (reading ‘x’)

Hi i figured it out i spelt Constructor wrong.

is the word constructor a special word in javascript?

yup

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.