Hello, i’m running an animate loop and trying to differentiate player and enemy shapes.
for some reason it keeps the last colour of the loop for all objects.
The canvas is clearing black but my objects and the hard coded shapes are all the last fill of green in my example
however when i shoot my projectile array it comes out yellow(as intented)
any ideas???
Blockquote
function animate(){
//refresh screen
window.requestAnimationFrame(animate)
c.fillStyle = "black";
c.fillRect(0,0,canvas.width,canvas.height)
//Draw Player
player.update()
//Draw Enemy
enemy.update()
c.beginPath
c.arc(100,100, 30, 0, Math.PI*2)
c.fillStyle = "pink"
c.fill();
c.closePath();
c.beginPath
c.arc(100,100, 30, 0, Math.PI*2)
c.fillStyle = "green"
c.fill();
c.closePath();
//projectiles
projectiles.forEach((projectile, index) => {
if(projectile.position.y + projectile.radius <= 0){
setTimeout(() => {
projectiles.splice(index,1)
},0)
}else{
projectile.update()
}
})