var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.NoteButton = function(buttonIndex) { this.buttonIndex = buttonIndex; EHDI.aka.Container.call(this); this.stringArmature = EHDI.GAME.dbFactory.buildArmature("string"); this.stringArmature.animation.gotoAndPlay("strum", -1, -1, 1); dragonBones.WorldClock.clock.add(this.stringArmature); this.stringSprite = this.stringArmature.getDisplay(); this.addChild(this.stringSprite); this.stringSprite.position.set(this.stringSprite.width * 2.5, this.stringSprite.height * 0.15); this.stringArmature.advanceTime(this.stringArmature.animation.animationDataList[0].duration); this.noteButtonSprite = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_default"]); this.noteButtonSprite.anchor.set(0.5, 0.5); this.noteButtonSprite.interactive = true; this.addChild(this.noteButtonSprite); this.position.set(EHDI.GAME.sceneManager.getStageWidth() * (0.356 + 0.09 * buttonIndex), EHDI.GAME.sceneManager.getStageHeight() * 0.85); var inputKey = 39 if(buttonIndex === 0) inputKey = 37; else if(buttonIndex === 1) inputKey = 40; else if(buttonIndex === 2) inputKey = 38; this.keyBoardInput = EHDI.interactions.Keyboard(inputKey); this.keyBoardInput.press = this.press.bind(this); this.hitArmature = EHDI.GAME.dbFactory.buildArmature("hit_anim"); this.hitArmature.animation.gotoAndPlay("hitend", -1, -1, 1); this.hitArmature.advanceTime(this.hitArmature.animation.animationDataList[0].duration) dragonBones.WorldClock.clock.add(this.hitArmature); this.hitSprite = this.hitArmature.getDisplay(); this.addChild(this.hitSprite); this.feedBackText = new EHDI.aka.Sprite(EHDI.Assets.images["kinnor_perfect"]); this.feedBackText.position.y = -this.noteButtonSprite.height * 0.5; this.feedBackText.anchor.set(0.5, 1); this.feedBackText.alpha = 0; this.addChild(this.feedBackText); this.noteButtonSprite.touchstart = this.press.bind(this); this.noteButtonSprite.mousedown = this.press.bind(this); } EHDI.components.NoteButton.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.components.NoteButton.prototype.press = function() { if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; if(this.pressTimeline) this.pressTimeline.kill(); this.pressTimeline = new TimelineMax(); this.pressTimeline.to(this.noteButtonSprite.scale, 0.075, {x : 0.85, y : 0.85}); this.pressTimeline.to(this.noteButtonSprite.scale, 0.075, {x : 1, y : 1}); this.default(); this.feedBackText.alpha = 0; var hitString = EHDI.GAME.gameScene.noteManager.hitNote(this.buttonIndex); if(hitString) { this.stringArmature.animation.gotoAndPlay("strum", -1, -1, 1); this.feedBackText.alpha = 1; this.feedBackText.y = - this.noteButtonSprite.height * 0.5; this.feedBackText.texture = EHDI.Assets.images["kinnor_" + hitString]; this.hitArmature.animation.gotoAndPlay("hitend", -1, -1, 1); this.pressTimeline.to(this.feedBackText, 0.5, {y: this.feedBackText.y - this.feedBackText.height * 0.25, alpha : 0}, 0); }; }; EHDI.components.NoteButton.prototype.error = function() { this.noteButtonSprite.texture = EHDI.Assets.images["kinnor_error"]; if(this.pressTimeline) this.pressTimeline.kill(); this.pressTimeline = new TimelineMax(); this.noteButtonSprite.scale.set(1, 1); this.feedBackText.alpha = 1; this.feedBackText.y = - this.noteButtonSprite.height * 0.5; this.feedBackText.texture = EHDI.Assets.images["kinnor_miss"]; this.pressTimeline.to(this.feedBackText, 0.5, {y: this.feedBackText.y - this.feedBackText.height * 0.25, alpha : 0}, 0); this.pressTimeline.add(this.default.bind(this)); EHDI.GAME.soundManager.playSFX("miss_sfx"); }; EHDI.components.NoteButton.prototype.default = function() { this.noteButtonSprite.texture = EHDI.Assets.images["kinnor_default"]; }; EHDI.components.NoteButton.prototype.dispose = function() { this.keyBoardInput.dispose(); }