Permalink
Browse files

1. Added visual comment referencing for MenuState.as.

2. Memory Inspection for MenuState.as passed with one situation needing review.
	Situation: Ensure menu classes are being reused or destroyed not recreated
  • Loading branch information...
kenny-gregory committed May 28, 2012
1 parent a59e2bd commit fdf66e27b7e2a1db7f94ac8c88aee4ceff96ac73
Showing with 1 addition and 1 deletion.
  1. +1 −1 Game/menu/MenuState.as
View
@@ -1 +1 @@
-package menu{ import core.Assets; import core.State; import org.flixel.FlxButton; import org.flixel.FlxEmitter; import org.flixel.FlxG; import org.flixel.FlxParticle; import org.flixel.FlxSound; import org.flixel.FlxSprite; import org.flixel.FlxState; import org.flixel.FlxText; ///////////////////////////////////////////////////////// [ CLASS ] //////////////////////////////////////////////////////////////////////////// public class MenuState extends FlxState { //button private var _playBtn:FlxButton; private var _aboutBtn:FlxButton; private var _helpBtn:FlxButton; private var _muteBtn:FlxButton; //particle private var theEmitter:FlxEmitter; private var whitePixel:FlxParticle; //text private var _info:FlxText; //sound private var _btnSound:FlxSound;///////////////////////////////////////////////////////// [ CONSTRUCTOR ] //////////////////////////////////////////////////////////////////////////// public function MenuState() { FlxG.mouse.show(null,1,0,0); initDisplayObjects(); FlxG.play(Assets.startSound); } /** * Init display objects */ private function initDisplayObjects():void { var bg:FlxSprite = new FlxSprite(); bg.loadGraphic(Assets.bgClass, false, false); bg.alpha = 0.5; bg.x = (FlxG.width - bg.width)/2; bg.y = (FlxG.height - bg.height)/2; add(bg); _playBtn = new FlxButton(); _playBtn.loadGraphic(Assets.btnPlayClass, false, false, 140,40); _playBtn.soundDown = getBtnSound(); _playBtn.x = (FlxG.width - _playBtn.width) / 2; _playBtn.y = FlxG.height / 3; _playBtn.onDown = playHandler; add(_playBtn); var padding:int = 10; _muteBtn = new FlxButton(); _muteBtn.loadGraphic(Assets.btnMuteClass, false, false, 32, 32); _muteBtn.soundDown = getBtnSound(); _muteBtn.onDown = optionHandler; _muteBtn.x = (FlxG.width - _muteBtn.width) / 2; _muteBtn.y = FlxG.height - _muteBtn.height - padding; add(_muteBtn); _aboutBtn = new FlxButton(); _aboutBtn.loadGraphic(Assets.btnProfileClass, false, false, 32, 32); _aboutBtn.soundDown = getBtnSound(); _aboutBtn.x = FlxG.width - padding - _aboutBtn.width; _aboutBtn.y = FlxG.height - padding - _aboutBtn.height; _aboutBtn.onDown = aboutHandler; add(_aboutBtn); _helpBtn = new FlxButton(); _helpBtn.loadGraphic(Assets.btnHelpClass, false, false, 32, 32); _helpBtn.soundDown = getBtnSound(); _helpBtn.x = padding; _helpBtn.y = FlxG.height - padding - _helpBtn.height; _helpBtn.onDown = helpHandler; add(_helpBtn); } /** * get button sound * @return */ private function getBtnSound():FlxSound { var snd:FlxSound = new FlxSound(); snd.loadEmbedded(Assets.btnSound); return snd; } private function goPlayHandler():void { FlxG.switchState(new State()); } /** * Go help handler * */ private function goHelpHandler():void { FlxG.switchState(new HelpState); } /** * Go play effect */ private function playHandler():void { FlxG.fade(0xFFFFFF, 1, goPlayHandler); } /** * Go about * */ private function goAboutHandler():void { FlxG.switchState(new AboutState); } /** * Go help effect */ private function helpHandler():void { FlxG.fade(0xffffff, 0.5, goHelpHandler); } /** * Go about effect */ private function aboutHandler():void { FlxG.fade(0xffffff, 0.5, goAboutHandler); } /** * Go option effect */ private function optionHandler():void { test(); } private function test():void { theEmitter = new FlxEmitter(100, FlxG.height / 2, 30); //so lets make them launch to the right. theEmitter.setXSpeed(-50, 50); //and lets funnel it a tad theEmitter.setYSpeed(-50, 50); //Let's also make our pixels rebound off surfaces theEmitter.bounce = .8; theEmitter.gravity = 100; //Now let's add the emitter to the state. add(theEmitter); //Now it's almost ready to use, but first we need to give it some pixels to spit out! //Lets fill the emitter with some white pixels for (var i:int = 0; i < theEmitter.maxSize; i++) { whitePixel = new FlxParticle(); whitePixel.makeGraphic(2, 2, 0xFFFFFFFF); whitePixel.visible = false; //Make sure the particle doesn't show up at (0, 0) theEmitter.add(whitePixel); whitePixel = new FlxParticle(); whitePixel.makeGraphic(1, 1, 0xFFFFFFFF); whitePixel.visible = false; theEmitter.add(whitePixel); } theEmitter.start(true, 1, .01); } }}
+/* Parent of: BaseOtherState.as AboutState.as HelpState.as OverState.as Memory Inspection: May,28 2012 (pass) Note: Ensure classes are being destroyed or re-used not recreated everytime. Otherwise code is sound.*/package menu{ import core.Assets; import core.State; import org.flixel.FlxButton; import org.flixel.FlxG; import org.flixel.FlxSound; import org.flixel.FlxSprite; import org.flixel.FlxState; import org.flixel.FlxText; ///////////////////////////////////////////////////////// [ CLASS ] //////////////////////////////////////////////////////////////////////////// public class MenuState extends FlxState { //button private var _playBtn:FlxButton; private var _aboutBtn:FlxButton; private var _helpBtn:FlxButton; private var _muteBtn:FlxButton; //text private var _info:FlxText; //sound private var _btnSound:FlxSound;///////////////////////////////////////////////////////// [ CONSTRUCTOR ] //////////////////////////////////////////////////////////////////////////// public function MenuState() { FlxG.mouse.show(null,1,0,0); initDisplayObjects(); FlxG.play(Assets.startSound); } /* --------------------------- */// Initialize Background/Buttons private function initDisplayObjects():void { var bg:FlxSprite = new FlxSprite(); bg.loadGraphic(Assets.bgClass, false, false); bg.alpha = 0.5; bg.x = (FlxG.width - bg.width)/2; bg.y = (FlxG.height - bg.height)/2; add(bg); _playBtn = new FlxButton(); _playBtn.loadGraphic(Assets.btnPlayClass, false, false, 140,40); _playBtn.soundDown = getBtnSound(); _playBtn.x = (FlxG.width - _playBtn.width) / 2; _playBtn.y = FlxG.height / 3; _playBtn.onDown = playHandler; add(_playBtn); var padding:int = 10; _muteBtn = new FlxButton(); _muteBtn.loadGraphic(Assets.btnMuteClass, false, false, 32, 32); _muteBtn.soundDown = getBtnSound(); _muteBtn.onDown = optionHandler; _muteBtn.x = (FlxG.width - _muteBtn.width) / 2; _muteBtn.y = FlxG.height - _muteBtn.height - padding; add(_muteBtn); _aboutBtn = new FlxButton(); _aboutBtn.loadGraphic(Assets.btnProfileClass, false, false, 32, 32); _aboutBtn.soundDown = getBtnSound(); _aboutBtn.x = FlxG.width - padding - _aboutBtn.width; _aboutBtn.y = FlxG.height - padding - _aboutBtn.height; _aboutBtn.onDown = aboutHandler; add(_aboutBtn); _helpBtn = new FlxButton(); _helpBtn.loadGraphic(Assets.btnHelpClass, false, false, 32, 32); _helpBtn.soundDown = getBtnSound(); _helpBtn.x = padding; _helpBtn.y = FlxG.height - padding - _helpBtn.height; _helpBtn.onDown = helpHandler; add(_helpBtn); } /* --------------------------- */// Return Button Sound private function getBtnSound():FlxSound { var snd:FlxSound = new FlxSound(); snd.loadEmbedded(Assets.btnSound); return snd; } /* --------------------------- */// Switch to Play State private function goPlayHandler():void { FlxG.switchState(new State()); } /* --------------------------- */// Switch to Help State private function goHelpHandler():void { FlxG.switchState(new HelpState); } /* --------------------------- */// Switch to About State private function goAboutHandler():void { FlxG.switchState(new AboutState); } /* --------------------------- */// Transition to Play Handler private function playHandler():void { FlxG.fade(0xFFFFFF, 1, goPlayHandler); } /* --------------------------- */// Transition to Help Handler private function helpHandler():void { FlxG.fade(0xffffff, 0.5, goHelpHandler); } /* --------------------------- */// Transition to About Handler private function aboutHandler():void { FlxG.fade(0xffffff, 0.5, goAboutHandler); } /* --------------------------- */// Transition to Option Handler private function optionHandler():void { // option menu } }//class}//package

0 comments on commit fdf66e2

Please sign in to comment.