Canvas colour help

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()
    }
})

Ok I have figures something out my enemy is a circle and it doesn’t seem to be closing the fill properly

Blockquote
c.beginPath
c.arc(this.position.x,this.position.y, 30, 0, Math.PI*2)
c.stroke()
c.fillStyle = “red”
c.fill();

do you have it on some sort of sandbox environment as well? that way it gets more easier to offer help, happy coding :slight_smile:

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