Hi I’m getting this error from the console: cc._EventListenerTouchOneByOne.checkAvailable(): Invalid EventListenerTouchOneByOne! CCEventListener.js:359
I’m using Cocos2d-js v3 and I’m trying to use the new eventmanager as documented here: http://cocos2d-x.org/docs/manual/framework/html5/v3/eventManager/en
I don’t know what I’m doing wrong. Here’s my code:
var BigGridLayer = cc.Layer.extend({
ctor: function() {
this._super();
this.init();
},
init: function() {
this._super();
//create a color layer
var gridBg = cc.LayerColor.create(cc.color(157, 155, 171, 60), 64 * 6, 768);
gridBg.setPosition(30, 50);
this.addChild(gridBg);
//create a custom sprite for our blocks
var BlockSprite = cc.Sprite.extend({
ctor: function(filename, rect) {
this._super(filename, rect);
this._active = false;
this._col;
this._row;
this._color;
this.init();
// Custom intialization
},
init: function() {
this._super();
cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchMoved: function(touch, event) {
//Move the position of current button sprite
console.log('touch moved');
var target = event.getCurrentTarget();
var delta = touch.getDelta();
target.x += delta.x;
target.y += delta.y;
},
}, this);
}
// add your properties and functions
});
//create a block sprite
var redBlock = new BlockSprite(res.red_png);
redBlock.attr({
x: 0,
y: 0,
anchorX: 0,
anchorY: 0
});
var newRedBlock = new BlockSprite(res.red_png);
newRedBlock.x = 64;
newRedBlock.anchorX = 0;
newRedBlock.anchorY = 0;
//create a block sprite
var blueBlock = new BlockSprite(res.blue_png);
blueBlock.attr({
x: 64 * 2,
y: 0,
anchorX: 0,
anchorY: 0
});
var newBlueBlock = new BlockSprite(res.blue_png);
newBlueBlock.x = 64 * 3;
newBlueBlock.anchorX = 0;
newBlueBlock.anchorY = 0;
//create a block sprite
var greenBlock = new BlockSprite(res.green_png);
greenBlock.attr({
x: 64 * 4,
y: 0,
anchorX: 0,
anchorY: 0
});
var newGreenBlock = new BlockSprite(res.green_png);
newGreenBlock.x = 64 * 5;
newGreenBlock.anchorX = 0;
newGreenBlock.anchorY = 0;
gridBg.addChild(redBlock);
gridBg.addChild(newRedBlock);
gridBg.addChild(blueBlock);
gridBg.addChild(newBlueBlock);
gridBg.addChild(greenBlock);
gridBg.addChild(newGreenBlock);
}
});