A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Background

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    7

    Background

    Hi Everyone!

    I am creating a short and simple flash application in AS3 and I need some help and advice. Possibly a link to a tutorial, some knowledge or scripting help.

    What I am wanting to create is application that responds to the following keyboard presses. The up, down, left and right keys.

    I want to position everything on the stage using AS3. I have a scenic background image (as a movie clip) and a character (also a movie clip).

    So my character is on stage facing to the right and there is some scenery behind.

    I want to do the following:

    When the left key is pressed, the character faces left and appears to be walking. When the key is released the character stops.

    When the right key is pressed, the character faces right and appears to be walking. When the key is released the character stops.

    When the up key is pressed, the character jumps up and lands back on the ground.

    When the down key is pressed, the character crouches down. When the key is released the character returns to normal.

    I have created movie clips of these movements, so walking, crouching down and up, jumping and stood still.

    I also have created the background images where the edges join to together.

    So in a nut shell hat I am wanting is: Different key presses play different movie clips and move the background moves (loops) in the correct direction giving the illusion the charcter is walking (when actually they don't move at all, just the background does.)

    Any suggestions?

    Thanks,
    Nick

  2. #2
    AS2 intolerant person
    Join Date
    Jan 2009
    Location
    Swansea
    Posts
    352
    How the movieclips are displayed is dependant on your methods, but the keyboard stuff works like this:

    actionscript Code:
    this.addEventlistener(KeyboardEvent.KEY_DOWN, onKey);

    function onKey(e:KeyboardEvent):void {
       switch(e.keyCode) {
          case Keyboard.KEYNAME_UPARROW:
             // apply code
             break;
          case Keyboard.KEYNAME_DOWNARROW:
             // apply code
             break;
          case Keyboard.KEYNAME_LEFTARROW:
             // apply code
             break;
          case Keyboard.KEYNAME_RIGHTARROW:
             // apply code
             break;

          default: // leave empty  
    }

  3. #3
    Junior Member
    Join Date
    Feb 2011
    Posts
    7
    Ahhhhh thank you! Hmmm now on to the looping background, should be fun...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center