I'm experimenting with creating a simple Cocos2d-js demo featuring clickable balls that can be moved. Here is how I am generating the balls:
var listener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: false,
onTouchBegan: ballTouchBeganEventHandler
});
var BallTile = cc.Sprite.extend({
ctor: function(image, position)
{
this._super();
var ballSize = g_settings.ballSize;
this.initWithFile(image, cc.rect(0, 0, ballSize, ballSize));
this.setPosition(position);
cc.eventManager.addListener(listener.clone(), this);
}
});
var ball1 = new BallTile(ballImage1, ballPosition1);
var ball2 = new BallTile(ballImage2, ballPosition2);
var ball3 = new BallTile(ballImage3, ballPosition3);
The issue I'm facing is that when I click on any of the balls, the event gets triggered three times (once for each ball) instead of just once for the specific ball clicked. Even though all the balls share the same event listener, my expectation was that it would only trigger for the individual ball clicked, not for every ball associated with the listener.
What could be causing this behavior?