I am creating a simple platform game in Flash CS5 and Action Script 3.0. When the player loses all his life, then I want to redirect the player to "Game over" where they can select the "Retry" button to restart the game.
There is a problem finding me One way to do this is by trying to accomplish my goal by doing the following:
- View = false everything (player, Background, etc.)
- Set the "Game Over" view = true on the clip (this is invisible during gameplay)
- "Game over" button button to hide the movie clip Press, then show all gameplay elements again
- reset
This is probably a multi Not a good method, but if it works, I am happy. I just want to summarize the "game over" screen and if the player clicks on the "try again" button, they can play from the beginning.
Now, the problem with its implementation above is that when I set all the gameplay elements to false then visual = really set, the game has stopped .. Keyboard input again Does not activate and game elements are shown but are not active. Am I not aware of the visual feature that I do not know? Is it a mess with the "state" of an object?
There are some snippets of code from the Action Script file ...
if (life> gt = 0) {// print life count} and {gameOverFlag = true ; // To hide the game objects, show the game on the menu coins. Platforms.lookable = false; Background. Visible = false; StartPosition.visible = false; ThePlayer.visible = false; GameOver.visible = true; // This is a movie clip with "Game Over" text and Game Over Trygain Button.Advent Alisoner (Mouse Event Stick, Playgain) has the "Retry" button; } Function playgain (Event: MouseIvent): Zero {// start playing again coins. Visible = true; Platforms.lookable = true; Background. Visible = true; Initial post Visible = true; ThePlayer.visible = True; }This code problem is more of an architecture problem. Personally, I create a
reset () function on all custom sections. In this function, I need to set that object to the default state; Set status, alpha, visible, custom property etc.To say it, it really depends on you, but for you a good design pattern will be the state design pattern.
Basically, you have a
statmanager in your game, which controls and controls the differentstate objectsState objects can represent different states of your game;Main menu ,play ,gameover ,reset , etc.Each
state will haveinitialized () , aend () and possibly aupdate () . When yourstatmanager switches states, except thisend () onstate , andstart () Will callstate . You can be in only onestate at a time, so it will easily explain your logic, depending on where you are in your game.In the
start () function, you can set all the essentials for that specific state. For example, for yourPlay state, thestart () function can add all keyboard / mouse event listeners, which you need to control your game. Inside theend () function, whatever you set up clears everything up. In theend () function for yourplay position, you will remove all keyboard / mouse event listeners for example. This means that it is impossible for the player to make any play logic unless they are in thePlay state, if yourstate updates in function (which is called every frame), you can check that in thePlay example, the player does not have any other live yet, or has reached the next level score .For the reset logic, in your
reset position, you can callreset () function on all your objects, or manually Set them the way through their game with states will look like this:Menmanu (play) - & gt;Reset (orInit state) - & gt;Run - & gt;GameWorld (Replay) - & gt;Reset - & gt;RunThere is no built-in logic to reset the object, you must take it for yourself to adopt a pattern such that it can help him.
Comments
Post a Comment