Question

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');
            });
Était-ce utile?

La solution

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 ...

Autres conseils

"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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top