0

I'm trying to add an event listener to the example here: http://www.luxanimals.com/blog/article/combining_easel_box2d

What I'm trying to do is, I changed the Bitmap to

var birdBMP = new createjs.Bitmap("images/bird.png");
            birdBMP.x = Math.round(Math.random()*500);
            birdBMP.y = -30;
            birdBMP.regX = 25;   // important to set origin point to center of your bitmap
            birdBMP.regY = 25; 
            birdBMP.snapToPixel = true;
            birdBMP.mouseEnabled = true;
            stage.addChild(birdBMP);
            box2d.createBird(birdBMP);

this. Now I'm trying to bind an event listener to this Bidmap object like this.

birdBMP.addEventListener("mousedown", function(evt){
    console.log("clicked");
});

But it doesn't work. I'm using same "demo.js" from that example. The only thing I change is the one above. Changing Bitmap to createjs.Bitmap and then add an eventHandler to the bitmap. Everything else is working fine, just can't add an eventHandler. Anyone have any idea about why this eventHandler isn't working?

Thank you.

Edit: Here is the demo.js from the link on top: http://www.luxanimals.com/tutorials/birds/js/demo.js

user1767833
  • 129
  • 2
  • 10
  • The object returned by createjs.Bitmap("images/bird.png") is probably a wrapper. What you need is the "inner" dom object (ex. ). – sabof Jul 19 '13 at 19:38
  • do you have the project online somewhere? from looking at the two snippets it doesn't seem wrong, and you are also using the latest version of easeljs/createjs? – olsn Jul 19 '13 at 19:59
  • Added it to the main post. – user1767833 Jul 19 '13 at 21:19

1 Answers1

0

I noticed that this demo is using an old EaselJS version that does not support addEventListener, but I also tested it with onPress and it doesn't work - since you have not invested a lot of time in this yet, I'd suggest you to check out the "official" EaselJS-Box2D example from the Sandbox on Github, which already features mouse-interaction:

Link: https://github.com/CreateJS/sandbox

Live example: http://sandbox.createjs.com/EaselJS_Box2dWeb/

(This is not a direct programmatical answer to your question, but I posted it as an answer, because the tutorial you are trying to adapt is outdated and doesn't work with the current standards of EaselJS and there are more up-to-date examples available)

olsn
  • 16,644
  • 6
  • 59
  • 65
  • This is great. I searched for some time for another Box2d-EaselJS sample but wasn't able to find any. Thank you. – user1767833 Jul 19 '13 at 21:17