Skip to main content
Participating Frequently
November 9, 2012
Question

How do I make an intro screen for my game?

  • November 9, 2012
  • 1 reply
  • 732 views

I have a working section of a maze game that runs entirely in an .as file but I'd like to have an intro screen in the main timeline before the main game is run. I'd like the trigger to move on to the second frame to be a keyboard input ("Press Space to play"). How can I do this?

My total code so far in frame 1 is this:

import flash.events.*;

function keyPressed (k:KeyboardEvent):void{

switch (k.keyCode) {

case(32): gotoAndStop(1);

}

}

stop();

I have the intro on the stage already when the program is run but the game doesn't stop on the stop(); statement, it just carries on and runs the maze generator so I get a maze overlaying my intro graphics.

The .as file is a complete program starting with "package {" etc. Could that be causing the problem?

Thank you.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
November 9, 2012

Have assigned an event listener for that function such as....

stage.addEventListener(KeyboardEvent.KEY_UP, keyPressed);

If your function is supposed to go to the second frame, should it be using gotoAndStop(2);  ?

helen269Author
Participating Frequently
November 9, 2012

Hmmmm.......

Thank you for replying. I tried the event listener but it didn't help. Now th egame goes straight to the maze without even flashing the intro screen up and when I move my man he keeps moving even when I release the arrow key.

My frame 1 code now looks like this:

     import flash.events.*;

     stage.addEventListener(KeyboardEvent.KEY_UP, keyPressed);

     gotoAndStop(2);

Yes, I made a silly mistake before about gotoAndStop(1)! Oops! :-)

Ned Murphy
Legend
November 9, 2012

You still need the keyPressed function and the stop you had in your first posting.  The event listener line I provided is what was missing from what you showed that is needed to make the function work.