1

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');
            });
Jason94
  • 13,320
  • 37
  • 106
  • 184

2 Answers2

0

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

ashbuilds
  • 1,401
  • 16
  • 33
  • This won't be compatible with Crafty's built-in collision stuff, though! I'd assume it would also fail if you switched from DOM to Canvas. – starwed Mar 08 '14 at 19:41
  • I give solution ,according to above condition ,and i am not test it for canvas,may be it fails on canvas,but it work for HTML element ! @starwed – ashbuilds Mar 08 '14 at 19:51
  • Sure, but the OP is already using a [game framework](http://craftyjs.com/) that provides this functionality; there's no reason for them to pull in additional dependencies that aren't compatible. :) – starwed Mar 08 '14 at 19:54
  • @starwed ,ya you right,but whatever i know to achieve above task,i just shared here !,And really i don't know anything about this tween/crafty plugin! :) anyway, If you wanna edit and have better answer then your welcome :) – ashbuilds Mar 08 '14 at 19:59
0

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

starwed
  • 2,536
  • 2
  • 25
  • 39
  • ,Please add any running example of `collision detection` with `craftyJs` ,because i searched alot but nothing find...it ! – ashbuilds Mar 08 '14 at 20:35