javascript - How to determine if a collision is new or continued from last frame -


i have function detects collision between objects. called within ticker (fps 60). if statement run long 2 objects together. think has ticker , running if every frame. best way fix example when 2 objects collided person gets 1 point instead of 4 or ten.

function colldec(){      var mindistance = 10 + 10;     var xdist = circle.x - arrow.x;     var ydist = circle.y - arrow.y;     var distance = math.sqrt(xdist*xdist + ydist*ydist);     if (distance < mindistance) {         lpoints.text = "points: " + ++pointsam;           //console.log("hit");          var dingsound = createjs.sound.play("sound/ding.mp3");              //reset();      }   } // end of colldec 

have int on each object, recently collided

if collision occurs, set both recently collided on both objects 2

at start of every frame, decrement recently collided on objects 1 minimum of 0

if collision occurs , recently collided 1 or higher* on both objects, not add points/play sound still increment recently collided.

*i think 'exactly 1' may fine too. seems matter in 'three balls collide simultaneously or near simultaneously' cases.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -