var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.MatchObject = function(assetName, column, row) { var width = 108, height = 98; var x = EHDI.GAME.sceneManager.getStageWidth() * 0.09 + ((width) * column) + (width * 0.5); var y = EHDI.GAME.sceneManager.getStageHeight() * 0.21 + ((height + 3) * row) + (height * 0.5); this.displaySprite = new EHDI.aka.Sprite(EHDI.Assets.images[assetName + "_btn1"]); //this.displaySprite = EHDI.displays.FillRectangle(color, x, y, width, height); this.assetName = assetName; this.displaySprite.position.set(x,y); this.displaySprite.alpha = 0; this.displaySprite.anchor.x = 0.5; this.displaySprite.anchor.y = 0.5; EHDI.aka.Container.call(this); this.addChild(this.displaySprite); this.fx = new EHDI.aka.Sprite(EHDI.Assets.images["gizmomatches_fx_explode"]); this.fx.anchor.set(0.5, 0.5); this.fx.scale.set(0, 0); this.fx.position.set(x,y); this.addChild(this.fx); }; EHDI.components.MatchObject.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.MatchObject.prototype.touchstart = function(touchData) { this.isTouched = true; this.touchID = touchData.data.identifier; this.displaySprite.scale.x = 0.7; this.displaySprite.scale.y = 0.7; }; EHDI.components.MatchObject.prototype.touchend = function(touchData) { this.displaySprite.scale.x = 1; this.displaySprite.scale.y = 1; if(this.isTouched) this.onClickFunction(); this.isTouched = false; }; EHDI.components.MatchObject.prototype.touchendoutside = function(touchData) { if(this.touchID !== touchData.data.identifier) return; this.displaySprite.scale.x = 1; this.displaySprite.scale.y = 1; if(this.isTouched) this.onClickFunction(); this.isTouched = false; }; EHDI.components.MatchObject.prototype.mousedown = function(touchData) { this.isTouched = true; this.displaySprite.scale.x = 0.7; this.displaySprite.scale.y = 0.7; }; EHDI.components.MatchObject.prototype.mouseup = function(touchData) { this.displaySprite.scale.x = 1; this.displaySprite.scale.y = 1; if(this.isTouched) this.onClickFunction(); this.isTouched = false; }; EHDI.components.MatchObject.prototype.mouseupoutside = function(mouseData) { this.displaySprite.scale.x = 1; this.displaySprite.scale.y = 1; if(this.isTouched) this.onClickFunction(); this.isTouched = false; }; EHDI.components.MatchObject.prototype.onClickFunction = function() { EHDI.GAME.matchManager.handleInput(this); }; EHDI.components.MatchObject.prototype.hideObject = function(isNext, addDelay) { addDelay = addDelay || 0; this.displaySprite.texture = EHDI.Assets.images["btn2_white"]; this.ignore = true; var options = {delay : addDelay}; if(isNext) options.onComplete = EHDI.GAME.matchManager.checkIfNext.bind(EHDI.GAME.matchManager); this.hideTimeline = new TimelineMax(options); this.hideTimeline.to(this.displaySprite.scale, 0.5, {x : 0, y : 0, ease: Back.easeIn}) this.hideTimeline.to(this.displaySprite, 0.5, {alpha : 0}, 0.1); this.hideTimeline.to(this.fx.scale, 0.1, {x : 1, y : 1}, 0.25); this.hideTimeline.to(this.fx, 0.7, {alpha : 0}, 0.25); }; EHDI.components.MatchObject.prototype.pauseTimeline = function() { if(this.hideTimeline) this.hideTimeline.pause(); }; EHDI.components.MatchObject.prototype.resumeTimeline = function() { if(this.hideTimeline) this.hideTimeline.play(); } EHDI.components.MatchObject.prototype.selectObject = function() { this.displaySprite.texture = EHDI.Assets.images[this.assetName + "_btn2"]; this.selected = true; }; EHDI.components.MatchObject.prototype.deselectObject = function() { this.displaySprite.texture = EHDI.Assets.images[this.assetName + "_btn1"]; this.selected = false; };