Search code examples
createjs

Collision between two objects ndgmr.checkPixelCollision


I am trying to detect for a collision between two objects that are wrapped inside of two different containers. I am using a collision detection script found here https://github.com/olsn/Collision-Detection-for-EaselJS/tree/master/example/js.

I can get the ndgmr.checkRectCollision working but then the transparent areas of my bitmaps are also dectected in the the collision which is to be expected based on the documentation ;) Swapping over to ndgmr.checkPixelCollision is causing an error in my console.

 TypeError: image is undefined
 ctx.drawImage(image,0,0,image.width,image.height); 

Anyone found out what the error means and how to get it working?


Solution

  • Solved, I just created a get function in MyObject class that returns my Sprite.

     var obj01 = new MyObject(loader.getResult("myObj"), 50, 50);
     var obj02 = new MyObject(loader.getResult("myObj"), 50, 50);
    
     var collision = ndgmr.checkPixelCollision(obj01.getImage(),obj02.getImage(), 1);
    

    Works perfectly!