Reputation: 33
use pixi.js create sprite and
var sprite = new PIXI.Sprite(textureSprite);
sprite.buttonMode = true;
sprite.position.x = _.provinces[0].posX;
sprite.position.y = _.provinces[0].posY;
// make the button interactive...
sprite.interactive = true;
sprite
// set the mousedown and touchstart callback...
.on('mousedown',onButtonDown)
.on('touchstart',onButtonDown);
how can I pass argument to event handler function onButtonDown? The same event handler can be bound to an element multiple times.
Upvotes: 3
Views: 2725
Reputation: 587
How about using an anonymous function?
sprite.on('mousedown',function(e) { onButtonDown(e,"hello"); });
You could also set a property on your sprite and then pick the property up from your onButtonDown
method using e.target
(which gives you the sprite that has been interacted with):
sprite.myCustomProperty = "hello";
// And then in your mousedown method:
var onButtonDown = function(e) {
var customProperty = e.target.myCustomProperty;
}
Upvotes: 3