javascript - How can i stop my animation circle ? - JS -



javascript - How can i stop my animation circle ? - JS -

i'm doing game javascript using function, know it's not best method i'm still learning prototypes before steping in utilize them. so, point, have request animatation frame calls him self function maintain executing. problem when player dies want stop enemys created , basicaly, stop functions execution. improve show code. animation function:

function animate() { if (endgame() == true) { return; } requestanimationframe(animate); if(thebird == null && cancontinue == true) { thebird = getbird(); // variavel com div bird settimeout(createdrake(), math.round(math.random() * 800)); settimeout(createbrick(), math.round(math.random() * 3000)); settimeout(createboss(), math.round(1000 + math.random() * 15000)); settimeout(createpowerup(), math.round(math.random() * 15000)); document.addeventlistener('keydown', onkeypressed); document.addeventlistener('keyup', onkeyreleased); } else { updatebirdlocation(); updatebirdspeed(); flydrakes(); flybrick(); flybullets(); flypowerup(); flyboss(); checkbulletcollisions(); checkbulletcollisionsbricks() checkshipcollision(); checkshipcollisionbricks(); checkshipcollisionbonusp(); checkshipcollisionboss(); checkbulletcollisionsboss(); updatescores(); checkenemybulletcollisions(); movearrayx(bullets2, -10); movearrayx(bullets3, -10); removepassingelements(); } }

and 1 function stopgame beeing called everytime player looses:

function endgame() { rbutton.style.visibility= "visible"; var restartdiv = document.createelement("div"); restartdiv.id = "restartdiv"; gamediv.appendchild(restartdiv); document.getelementbyid('restartdiv').innerhtml += "you scored" + " " + mobhits + " " + "points!"; cancontinue = false; homecoming true; }

my attemp stop 1st part of animate :

function animate() { if (endgame() == true) { return; }

but if game stops ( want ) before player dies.

i not have endgame beeing executed anywhere besides functions player dies. how can solve ?

thank you

edit: illustration how observe player died:

function checkshipcollisionboss() { (var k=0; k<bossarray.length; k++) { if ((iscollide(birdsdiv, bossarray[k]) ) == true){ endgame(); } } }

iscollide function detects collision.

then this,

function endgame() { if(iscollide()) // homecoming boolean function { rbutton.style.visibility= "visible"; var restartdiv = document.createelement("div"); restartdiv.id = "restartdiv"; gamediv.appendchild(restartdiv); document.getelementbyid('restartdiv').innerhtml += "you scored" + " " + mobhits + " " + "points!"; cancontinue = false; homecoming true; } homecoming false; }

also remember this, if going check boolean can simple give

if(true) or if (false)

example,

var bool = true; if(bool) // stuff

javascript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -