Jump to content
Search Community

Edge Animate - How to do hitTest?

TomW test
Moderator Tag

Go to solution Solved by Diaco,

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm a newbie, trying to get Edge Animate to perform a hitTest on two elements when one is dropped (see attached). Seems like it should work but I'm stumped.  Any ideas?

 

Draggable.create(sym.$("dragger"), { 
onDragEnd:function() {
alert("dropped");
checktarget()
}
});
 
function checktarget(){
alert("checktarget");
if (sym.$("dragger").hitTest(sym.$("target"))) {
alert("hit");
}
}
 

drag.zip

Link to comment
Share on other sites

  • Solution

Hi TomW  :)

 

Pls try this :

Draggable.create(sym.$("dragger"), { 
   onDragEnd:checktarget
});

function checktarget(){
   if ( this.hitTest(sym.$("target")) ) {
      alert("hit");
   }
}

Oh ! , and you Need to Update your GSAP js files :

 

your files = TweenMax 1.11.4 , Draggable 0.9.9

 

GSAP last release  = TweenMax 1.16.1 , Draggable 0.13.0 ,  ( updated 2015-04-09  )

  • Like 3
Link to comment
Share on other sites

  • 6 months later...

Hi a7med.flash :)

 

you can use static version of Draggable hit test :

var Blue = document.querySelector('#blue');
var Red = document.querySelector('#red');

TweenLite.to(Red,2,{x:300,onUpdate:function(){
    var hit = Draggable.hitTest( this.target , Blue , 10 );
    console.log(hit);
}});

or use js 2D collision detection methods ( same as above code , check with onUpdate fn ) :

https://developer.mozilla.org/en-US/docs/Games/Techniques/2D_collision_detection

  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...