actionscript 3 - AS3 HitTestPoint stops working with Array object -


the player falls through ground displayobject after few frames. how can stop him doing it?

this function called every frame enter_frame in mainloop of game.

public function groundcollision() {         each(var moveg: displayobject in groundmovearray) {             if (moveg.hittestpoint(player.x + downbumppoint.x, player.y + downbumppoint.y, true)) {                 bumping = true;             } else {                 bumping = false;             }         }         if (bumping == true) {             if (yspeed >= 0) {                 yspeed = 0;             }             if (jumppressed) {                 yspeed = jumpconstant;             }         } else {             yspeed += gravityconstant;         }         yspeed *= friction;         playery += yspeed;         player.y = playery;     } 

for each(var moveg: displayobject in groundmovearray) {     if (moveg.hittestpoint(player.x + downbumppoint.x, player.y + downbumppoint.y, true)) {         bumping = true;     } else {         bumping = false;     } } 

here check player against ground blocks in loop. player can intersect 1 block @ once. if intersects 1 block, not intersect other. checking in loop, bumping flag assigned result last checked block. if there 2 blocks, , player intersects first block, check finish bumping == false because last block checked not 1 intersects player. player fall down.

you need add break statement after bumping = true exit loop.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -