zoomla
Version:
16年专业研发|中文alexa排名第一的CMS品牌-基于dotNET core、功能强大,集成站群、微信开发、小程序与ERP及OA办公系统,支持国际语言和多民族语言,世界五百强与大型门户专用高端网站内核CMS系统
63 lines (59 loc) • 2.55 kB
JavaScript
var GlassSprite = cc.Sprite.extend({
disappearAction: null,//消失动画
touchListener: null,
index: null,//在数组中的索引
onEnter: function () {
cc.log("onEnter");
this._super();
//this.disappearAction = this.createDisappearAction();
//this.disappearAction.retain();
this.addTouchEventListenser();
},
onExit: function () {
cc.log("onExit");
//this.disappearAction.release();
this._super();
},
createDisappearAction: function () {
//var frames = [];
//for (var i = 0; i < 11; i++) {
// var str = "sushi_1n_" + i + ".png"
// var frame = cc.spriteFrameCache.getSpriteFrame(str);
// frames.push(frame);
//}
//var animation = new cc.Animation(frames, 0.02);
//var action = new cc.Animate(animation);
//return action;
},
addTouchEventListenser: function () {
this.touchListener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
// When "swallow touches" is true, then returning 'true' from the onTouchBegan method will "swallow" the touch event, preventing other listeners from using it.
swallowTouches: true,
onTouchBegan: function (touch, event) {
//var pos = touch.getLocation();
var target = event.getCurrentTarget();
var locationInNode = target.convertToNodeSpace(touch.getLocation());
var s = target.getContentSize();
var rect = cc.rect(0, 0, s.width, s.height);
if (cc.rectContainsPoint(rect, locationInNode)) {//这样直接可拖动,move则为移动动画
cc.log("sprite began... x = " + locationInNode.x + ", y = " + locationInNode.y);
//target.setOpacity(180);
//target.getAnimation().play("move");
return true;
}
return false;
},
onTouchMoved: function (touch, event) {
var target = event.getCurrentTarget();
var delta = touch.getDelta();
target.x += delta.x;
target.y += delta.y;
}
});
cc.eventManager.addListener(this.touchListener, this);
},
removeTouchEventListenser: function () {
cc.eventManager.removeListener(this.touchListener);
}
});