0

I am developing a Cocos2d-HTML5 based game. I am trying to handle mouse click event in my code like below. This is added in 'cc.Layer.extend' class. When i tested the code, it is not detecting the mouse click event, it is doing nothing when i click through mouse. Please suggest what is wrong in my code and how can i handle mouse click event in the layer created for a scene?

Approach 1 : 
    var closemenuItem = cc.MenuItemImage.create(
    "res/FamilyRoomButton.png",
    "res/FamilyRoomButton.png",
    function () {
    alert("Works");
    },this);
    closemenuItem.setAnchorPoint(cc.p(0.5, 0.5));

    var menu = cc.Menu.create(closemenuItem);
                menu.setPosition(cc.PointZero());
                this.addChild(menu, 1);
                closemenuItem.setPosition(cc.p(size.width - 20, 20));
    Approach 2:
      var item1 = new cc.MenuItemFont.create("FamilyRoomButton",this,this.playSound);
         item1.setPosition(500,500);
           var menu = cc.Menu.create(item1);
          menu.setPosition(new cc.Point(0,0));
            this.addChild(menu);
    playSound:function()
       {
                alert("Play Works!!!");
        }

1 Answers1

0

have you add

this.setMouseEnabled(true);

in your init:function() ??

Student Jack
  • 1,025
  • 2
  • 14
  • 19