我正在开发一个基于cocos2d-HTML 5的游戏。我试图在我的代码中处理鼠标点击事件,如下所示。这是在'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!!!");
}发布于 2014-04-06 01:58:07
你加了吗
This.setMouseEnabled(真);
在您的init中:function()?
https://stackoverflow.com/questions/16481702
复制相似问题