0

我正在开发一个基于 Cocos2d-HTML5 的游戏。我正在尝试在我的代码中处理鼠标单击事件,如下所示。这是在 'cc.Layer.extend' 类中添加的。当我测试代码时,它没有检测到鼠标点击事件,当我点击鼠标时它什么也没做。请建议我的代码有什么问题以及如何在为场景创建的图层中处理鼠标单击事件?

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!!!");
        }
4

1 回答 1

0

你加了吗

this.setMouseEnabled(true);

在你的 init:function() 中?

于 2014-04-06T01:58:07.057 回答