(function() { "use strict"; var MenuScene = function() { this.initialize(); } var p = MenuScene.prototype = new creatine.Scene(); p.Scene_initialize = p.initialize; p.initialize = function() { this.Scene_initialize(); // initialize objects this.background = new createjs.Bitmap(loader.getResult('img_bg')); this.logo = new createjs.Bitmap(loader.getResult('img_logo')); var bounds = this.logo.getBounds(); this.logo.regX = bounds.width/2; this.logo.regY = bounds.height/2; this.logo.x = canvas.width/2; this.logo.y = bounds.height/2+15; this.buttonToogleSound = new createjs.Bitmap(loader.getResult('img_button_sound')); var bounds = this.buttonToogleSound.getBounds(); this.buttonToogleSound.regX = bounds.width; this.buttonToogleSound.regY = bounds.height; this.buttonToogleSound.x = canvas.width-20; this.buttonToogleSound.y = canvas.height-20; this.buttonStart = new Button('Start'); this.buttonCredits = new Button('Credits'); this.buttonGuineaLink = new createjs.Text('http://guineashots.com', '24px sheep', '#333'); this.time = Math.random()*2 + 1; // set layout var area = {x:0, y:0, width:canvas.width, height:canvas.height} var vbox = new creatine.BoxSizer(creatine.VERTICAL, area); vbox.add({}, 11, 0) vbox.add(this.buttonStart, 3, 0, creatine.CENTER); vbox.add(this.buttonCredits, 3, 0, creatine.CENTER); vbox.add({}, 3, 0) vbox.add(this.buttonGuineaLink, 1, 5, creatine.CENTER) vbox.add({}, 1, 0) vbox.layout(); // add objects to scene this.addChild(this.background); this.addChild(this.logo); this.addChild(this.buttonToogleSound); this.addChild(this.buttonStart); this.addChild(this.buttonCredits); this.addChild(this.buttonGuineaLink); // register events this.on('sceneenter', this.onSceneEnter); this.on('sceneresume', this.onSceneResume); this.on('scenepause', this.onScenePause); } p.registerEvents = function(event) { this.buttonStart.on('click', this.onButtonStart, this); this.buttonCredits.on('click', this.onButtonCredits, this); this.buttonGuineaLink.on('click', this.onGuineaLink, this); this.buttonToogleSound.on('click', jukebox.toggleSound); } p.unregisterEvents = function(event) { this.buttonStart.removeAllEventListeners('click'); this.buttonCredits.removeAllEventListeners('click'); this.buttonGuineaLink.removeAllEventListeners('click'); this.buttonToogleSound.removeAllEventListeners('click'); } p.onUpdate = function(event) { if (this.time < 0) { this.time += Math.random()*10 + 3; createjs.Tween.get(this.logo) .to({rotation:30}, 200) .to({rotation:-30}, 200) .to({rotation:30}, 200) .to({rotation:-30}, 200) .to({rotation:15}, 200) .to({rotation:-15}, 200) .to({rotation:5}, 200) .to({rotation:0}, 200) } this.time -= event.fdelta; } p.onSceneEnter = function(event) { this.registerEvents(); } p.onSceneResume = function(event) { this.registerEvents(); } p.onScenePause = function(event) { this.unregisterEvents(); } p.onGuineaLink = function(event) { window.open('http://guineashots.com', '_blank'); } p.onButtonStart = function(event) { director.replace( new SelectLevelScene(), new creatine.transitions.Scroll(creatine.LEFT) ) } p.onButtonCredits = function(event) { director.push( new CreditsScene(), new creatine.transitions.Scroll(creatine.LEFT) ) } window.MenuScene = MenuScene; }());