javascript - Collision detection on a tweened object -
i cann't work, seems tweened objects don't fire 'moved' event?
i'm tweening object across screen, , need check if collided player (that flies , down keyboard events). works if append check on 'moved' player, if player stands still :-)
so need check when tweened objects moves if hit player
does not fire of events:
// astroid crafty.e('astroid, 2d, dom, color, tween, collision') .attr({ x: 600, y: 550, w: 50, h: 200 }) .color('#8e44ad') .tween({ x: -50 }, 4000) .bind('moved', function () { console.log('moved'); if (this.hit('player1')) { console.log('player hit 1'); } }) .onhit('player', function () { console.log('player hit 2'); });
updated :
i using little plugin
here ,collisions($div1, $div2)
:
so,
function interval() { timeout = settimeout(function () { if (collisions($('.player1'), $('.astroid'))) { alert('true'); } else{ interval(); } }, 25); } interval()
may helpful ...
Comments
Post a Comment