var EHDI = EHDI || Object.create(null); EHDI.scene = EHDI.scene || Object.create(null); EHDI.scene.GameScene = function (){ PIXI.Container.call(this); this.gameLayer = new EHDI.aka.Container(); this.guiLayer = new EHDI.aka.Container(); this.matchLayer = new EHDI.aka.Container(); this.addChild(this.gameLayer); this.addChild(this.guiLayer); // console.log(this); // this.addChild(bg); } EHDI.scene.GameScene.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.scene.GameScene.prototype.screenWillAppear = function() { this.bg = new EHDI.aka.Sprite(EHDI.Assets.images["gizmomatch_bg"]); this.gameLayer.addChild(this.bg); // this.createDragonBones(); this.createAnimations(); this.bg.errorSprite = new EHDI.aka.Sprite(EHDI.Assets.images["gizmomatch_bg_red"]); this.gameLayer.addChild(this.bg.errorSprite); this.bg.errorSprite.visible = false; this.bg.error = function() { this.errorSprite.visible = true; } this.bg.hideError = function() { this.errorSprite.visible = false; } }; EHDI.scene.GameScene.prototype.screenDidAppear = function() { //this.setupPauseButton(); var pauseButton = new EHDI.components.pauseButton(); this.guiLayer.addChild(pauseButton); this.addChild(this.matchLayer); EHDI.GAME.matchManager = new EHDI.components.MatchManager(this.matchLayer, this.bg); EHDI.GAME.scoreManager = EHDI.components.ScoreManager(this.guiLayer); EHDI.GAME.scoreManager.setXY(EHDI.GAME.sceneManager.getStageWidth() * 0.3, EHDI.GAME.sceneManager.getStageHeight() * 0.015); EHDI.GAME.timer = new EHDI.components.Timer(); EHDI.GAME.timer.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.025, EHDI.GAME.sceneManager.getStageHeight() * 0.015); this.guiLayer.addChild(EHDI.GAME.timer); this.matchTimeline = new TimelineMax({repeat : -1}) this.matchTimeline.to(this.matchLayer, 1, {y: this.matchLayer.y + 2, ease: Power0.easeNone}); this.matchTimeline.to(this.matchLayer, 2, {y: this.matchLayer.y - 4, ease: Power0.easeNone}); this.matchTimeline.to(this.matchLayer, 1, {y: this.matchLayer.y, ease: Power0.easeNone}); EHDI.GAME.updateManager.addFrameListener(this.animateAnimations); var cache = EHDI.GAME.saveData; if(cache.isFirstTimePlay) { EHDI.GAME.matchManager.touchEndAll(); EHDI.GAME.pauseButton.isPaused = true; EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.HTPPopUp(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.25}); cache.isFirstTimePlay = false; EHDI.sbGame.saveGameData(EHDI.GAME.saveData, "DEFAULT", function(){ console.log("data saved."); }); } this.bg.touchendoutside = function() { EHDI.GAME.matchManager.touchEndAll(); } this.startAmbientTimeline(); EHDI.GAME.soundManager.playSFX("ambient01"); }; EHDI.scene.GameScene.prototype.startAmbientTimeline = function() { if(this.ambientTimeline) this.ambientTimeline.kill(); this.ambientTimeline = new TimelineMax(); this.ambientTimeline.add(this.playAmbientSFX, "+=" + EHDI.NumberUtil.randomRange(5, 10)); this.ambientTimeline.add(this.startAmbientTimeline.bind(this), "+=1"); }; EHDI.scene.GameScene.prototype.playAmbientSFX = function() { EHDI.GAME.soundManager.playSFX("ambient0" + Math.floor(EHDI.NumberUtil.randomRange(2, 5))); } EHDI.scene.GameScene.prototype.setupPauseButton = function() { this.pauseButton = new EHDI.displays.Button(EHDI.Assets.images["pause-button-fs8"], EHDI.Assets.images["pause-button-on-hit-fs8"]); this.pauseButton.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.9, EHDI.GAME.sceneManager.getStageHeight() * 0.15); this.guiLayer.addChild(this.pauseButton); this.pauseButton.setOnClickFunction(this.onPauseClick.bind(this)); }; EHDI.scene.GameScene.prototype.createDragonBones = function() { EHDI.GAME.dbFactory = new dragonBones.PixiFactory(); var textureImage = EHDI.Assets.images["gizmomatch_tex"].baseTexture.source; var textureData = EHDI.Assets.cjAssets.getResult("gizmomatch_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); var skeleton = EHDI.Assets.cjAssets.getResult("gizmomatch_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); }; EHDI.scene.GameScene.prototype.animateAnimations = function(dt) { if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; dragonBones.WorldClock.clock.advanceTime(dt * 0.001) }; EHDI.scene.GameScene.prototype.createAnimations = function(dt) { this.glow = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.glow); this.glow.animation.gotoAndPlay("glow", -1, -1, 0); this.glowSprite = this.glow.getDisplay(); this.glowSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.185, EHDI.GAME.sceneManager.getStageHeight() * 0.175); this.gameLayer.addChild(this.glowSprite); this.lineGraph = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.lineGraph); this.lineGraph.animation.gotoAndPlay("linegraph", -1, -1, 0); this.lineGraphSprite = this.lineGraph.getDisplay(); this.lineGraphSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.968, EHDI.GAME.sceneManager.getStageHeight() * 0.915); this.gameLayer.addChild(this.lineGraphSprite); this.radar = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.radar); this.radar.animation.gotoAndPlay("radar", -1, -1, 0); this.radarSprite = this.radar.getDisplay(); this.radarSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.719, EHDI.GAME.sceneManager.getStageHeight() * 0.921); this.gameLayer.addChild(this.radarSprite); this.lowLeft = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.lowLeft); this.lowLeft.animation.gotoAndPlay("low_left_1", -1, -1, 0); this.lowLeftSprite = this.lowLeft.getDisplay(); this.lowLeftSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.065, EHDI.GAME.sceneManager.getStageHeight() * 0.955); this.gameLayer.addChild(this.lowLeftSprite); this.lowLeft2 = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.lowLeft2); this.lowLeft2.animation.gotoAndPlay("low_left_2", -1, -1, 0); this.lowLeft2Sprite = this.lowLeft2.getDisplay(); this.lowLeft2Sprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.186, EHDI.GAME.sceneManager.getStageHeight() * 0.9675); this.gameLayer.addChild(this.lowLeft2Sprite); this.lowRight = EHDI.GAME.dbFactory.buildArmature("ambient_an"); dragonBones.WorldClock.clock.add(this.lowRight); this.lowRight.animation.gotoAndPlay("low_right", -1, -1, 0); this.lowRightSprite = this.lowRight.getDisplay(); this.lowRightSprite.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.885, EHDI.GAME.sceneManager.getStageHeight() * 0.957); this.gameLayer.addChild(this.lowRightSprite); }; EHDI.scene.GameScene.prototype.popUpDidAppear = function() { this.matchTimeline.pause(); EHDI.GAME.matchManager.pauseAll(); this.ambientTimeline.pause(); } EHDI.scene.GameScene.prototype.popUpDidDisappear = function () { if(this.matchTimeline.isEndGame) return; this.matchTimeline.play(); this.ambientTimeline.play(); EHDI.GAME.matchManager.resumeAll(); EHDI.GAME.soundManager.resumeBGM(); }; EHDI.scene.GameScene.prototype.screenDidDisappear = function() { EHDI.GAME.updateManager.removeFrameListener(this.animateAnimations); dragonBones.WorldClock.clock.clear(); this.ambientTimeline.kill(); EHDI.GAME.timer.dispose(); this.matchTimeline.kill(); EHDI.GAME.scoreManager.dispose(); delete this.matchTimeline; this.destroy({children : true}); delete this; delete EHDI.GAME.matchManager; delete EHDI.GAME.scoreManager; delete EHDI.GAME.timer; };