I cann't get it to work, seems like tweened objects don't fire the 'Moved' event?

I'm tweening a object across the screen, and need to check if it collided with the player (that flies up and down by the keyboard events). It works if I append the check on 'Moved' for the player, but what if the player stands still :-)

So I need to check when the tweened objects moves if it hit the player

Does not fire any of the 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 am using little plugin Here ,collisions($div1, $div2):

So,

 function interval() {

   timeout = setTimeout(function () {

        if (collisions($('.player1'), $('.astroid'))) {
           alert('true');

        }
        else{
            interval();
        }
    }, 25);

 }

 interval()

WORKING DEMO

May this was helpful ...

其他提示

"Moved" is a special event that the components like "Multiway" use.

The more fundamental event is just "Move", which is implemented directly by the 2D component -- bind to that event instead.

What many people do is just check for collisions once per frame using "EnterFrame". If you need to act directly after the collision, binding to "Move" will provide that, though.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top