Skip to content

Commit

Permalink
added PIXI.EventTarget in Element for interactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Kelm committed Aug 8, 2013
1 parent 28e5a41 commit 60b147e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/MCT/Display/Object.js
Expand Up @@ -221,16 +221,16 @@ MCT.DisplayObject.prototype.createButton = function(options) {
}

MCT.DisplayObject.prototype.setInteraction = function(sprite, options) {
if (typeof options.action != "undefined" && typeof options.type != "undefined") {
if (options.element instanceof MCT.Element && typeof options.type != "undefined") {
sprite.setInteractive(true);
var callback = function() {
options.element.dispatchEvent( { type: options.type, content: options.data } );
};
switch (options.type) {
case "click":
sprite.click = options.action;
sprite.click = callback;
break;
}
if (typeof options.data != "undefined") {
sprite.mctInteractionData = options.data;
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/MCT/Element.js
Expand Up @@ -26,6 +26,9 @@ MCT.Element = function(name) {
this.name = name || "random" + Math.floor(Math.random() * 1000);
this.grid = null;
this.layout = null;
// use pixi event target to handle display object interaction events
// see -> https://github.com/MKelm/pixi.js/blob/dev/src/pixi/utils/EventTarget.js
PIXI.EventTarget.call(this);
}

MCT.Element.prototype.constructor = MCT.Element;

0 comments on commit 60b147e

Please sign in to comment.