WDI-SEA / game-project-issues

0 stars 0 forks source link

Humans/boosters to spawn at random interval #22

Closed hannahlegros closed 3 years ago

hannahlegros commented 3 years ago

What's the problem you're trying to solve?

I can't seem to get my humans or boosters to duplicate at all, let alone at a random interval.

Post any code you think might be relevant (one fenced block per file)

const playGame = () => {
    ctx.clearRect(0, 0, game.width, game.height)
    alien.create()
    alien.moveAlien()
    // human.create
    human.moveHuman()
    if(booster.alive){
        booster.create()
        booster.moveBooster()
        gainBooster()
    }
    humanHit()
    winOrLose()
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

No error message. My human either doesn't spawn or its form disappears from my canvas (effects are still seen), depending on different methods I've tried.

What is your best guess as to the source of the problem?

I'm not using a right method for spawning.

What things have you already tried to solve the problem?

I've mostly tried setInterval (even just to get them to spawn at a regular interval - didn't work) or setTimeout within a function. Moved those around to different parts of my code.

DoireannJane commented 3 years ago

Let's take a look at your .create()

hannahlegros commented 3 years ago

Still an unsolved issue.

hannahlegros commented 3 years ago

Added a global var that pushed each human into an empty array. Then used a forEach loop within my play game function to iterate through each human to create them and make them move. I added a setInterval within my initiate game function and passed it the function that created the array.