actionscript 3 - Objects keep disappearing, even though the HitTest object is removed -
i have been trying create game in actionscript 3, stuck on 1 problem past 4 hours. every time press key block appears, color depends on key press, when enemies hit block dissapear. made enemies removed through removechild , block dissapears after 1 second, problem after block gets removed enemies still die, though block isn;t visible anymore, here am.
i use code in vechtblok.as (this block appears kill enemies), add code adding eventlistener timer named sterf, function:
public function gaweg(e:timerevent):void { blok.parent.removechild(blok); }
in vijand.as (the enemy class) have code them dissapear, give enemies code through adding eventlistener:
public function aanval(e:event):void { if(hittestobject(vechtblok.blok)) { teken.removeeventlistener(event.enter_frame, beweeghor); trace(string(watbenik)); teken.parent.removechild(teken); //removechild(vechtblok.blok); } }
i think error should there somewhere, head hurts time spend on trying fix it.
thanks in advance , sorry broken english. cheers.
based on code , can understand it, you're not updating code such vechtblok.blok
no longer referring same block after removes itself. hittestpoint
, hittestobject
checks collisions using bounds of objects, regardless or whether or not on stage.
judging static variable vechtblok.blok
support 1 block @ time. once block removed, variable still pointing it. it's no longer displayed on stage. collision code still checking against same block.
you have modify code this:
public function gaweg(e:timerevent):void { blok.parent.removechild(blok); blok = null; }
;
public function aanval(e:event):void { if(vechtblock.blok != null && hittestobject(vechtblok.blok))
this way collision check happens when there block.
Comments
Post a Comment