Flash scene issue
I am having an issue with some flash scene stuff. I have never really messed with flash before, and I have to make a game for someone, and I hit this. I wanted to have 2 scenes, one开发者_如何学Go with the starting menu and the other with the actual game. First question, is that how that is usually done? Second, I don't know if this is what scenes do usually, but with the 2 in there, it flashes between the two scenes, and if I hit enter, it stops on whatever scene it was on, this is with a completely new project, so there isn't any code at all in there. If you have anywhere you can point me, let me know. Thanks in advance!
WWaldo
An answer for the first question: actually you're talking about simple game framework for flash platform. The one that I've used is based on state machine approach. Every state represents some game element (menu or actual game, in your case):
public static const STATE_SCENE_1:int = 10;
public static const STATE_SCENE_2:int = 20;
public static const STATE_GAME_OVER:int = 30;
public var gameState:int = 0;
Next you need to switch game states (from menu to game for example), the best practice is to use main game loop:
public function gameLoop(e:Event):void {
switch(gameState) {
case STATE_SCENE_1 :
initScene1();
break
case STATE_SCENE_2:
initScene2();
break;
case STATE_GAME_OVER:
gameOver();
break;
}
}
Notice that the previous code has a function named gameLoop(), you need to call it iteratively by a timer tick events or by ENTER_FRAME event:
public function Game() {
addEventListener(Event.ENTER_FRAME, gameLoop);
gameState = STATE_INIT;
}
After this, all your game processing will transfer to initScene1() function. There you can add your starting menu and animate it as you need.
Here in initScene2() goes your game logic. You can create enemies, make them move and other logic.
public function initScene2():void {
makeEnemies();
moveEnemies();
testCollisions();
testForEnd();
}
Next, if the main game logic decides to finish the game, you need to switch state to STATE_GAME_OVER and show player's results in gameOver() function. To get more details about game frameworks you can use "The Essential Guide to Flash Games" by Jeff Fulton and Steve Fulton.
Hope this helps.
Yeah, to answer your one question, The Flash IDE at it's dumbest is something that makes 'movies' based on frames. Scenes can be created to hold those frames. You'll need to manually add a stop();
command to the actions of each frame.
Whether or not it's right way to go is a matter of choice. I personally find it frustrating to toggle between Scenes, and if possible, will not use multiple frames either. It's usually much more efficient to add/remove different MovieClips, and use code to control their states, etc.
To create a game, you'll need to know some in/outs of working with classes and code frameworks, though maybe not much. You can go a long way with just exporting symbols from the library and what not. AS3 is the way to go, every time.
a very good link: http://as3gamedev.blogspot.com/
精彩评论