How to determine the animation is clicked, use MenuItme to achieve?
怎么确定动画被点击,然后触发事件,现在用ccTouchEnded 已经解决,想问哈能不能用MenuItme的方法实现!望高手解答!
怎么确定动画被点击,然后触发事件,现在用ccTouchEnded 已经解决,想问哈能不能用MenuItme的方法实现!望高手解答!
//simple realization :D
var testLayer = cc.Layer.extend({
init:function(){
var a = new cc.Sprite();
a.initWithFile("Resources/CloseNormal.png");
a.setPosition(cc.ccp(111,111))
this.addChild(a);
this.setIsTouchEnabled(true);
return true;
},
registerWithTouchDispatcher:function () {
cc.TouchDispatcher.sharedDispatcher().addTargetedDelegate(this, cc.CCMENU_TOUCH_PRIORITY, true);
},
ccTouchBegan:function(touch,e){
var a = this._itemForTouch(touch);
if(a){
console.log(a)
//do something
}
},
_itemForTouch:function (touch) {
var touchLocation = touch.locationInView(touch.view());
if (this.getChildren()) {
var child;
for (var i = 0; i < this.getChildren().length; i++) {
child = this.getChildren()[i];
if (child instanceof cc.Sprite && child.getIsVisible()) {
var local = child.convertToNodeSpace(touchLocation);
var r = child.boundingBox();
r.origin = cc.PointZero();
if (cc.Rect.CCRectContainsPoint(r, local)) {
return child;
}
}
}
}
return null;
}
});
testLayer.create = function(){
var tmplayer = new testLayer();
if(tmplayer.init()){
return tmplayer;
}
}
testLayer.scene = function(){
var scene = cc.Scene.create();
var layer = testLayer.create();
scene.addChild(layer);
return scene;
}