• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Flash Platform Game - Scrolling

Hello all;

I need to be able to use Action Script to make a scrolling background for a platform flash game I am making. Currently, I have 2 layers. One called background with all my objects on it, and one with my character on it. What I need is for when the character hits near the edge of the wall, the background will move along with it.

I have found the following tutorial, and it is what I want, but the tutorial does not have enough information to complete it.
Link: http://www.how2flash.com/tutorials/sGame/

What would I use to make it a scrolling background like that with my current setup?

Thanks.
0
dh-s
Asked:
dh-s
1 Solution
 
psyki_beCommented:
Well, like the tutorial says.
there's 2 ways to make a scrolling game.

1) fixed camera: the background will constantly move when you move the character.
this can be done by doing this:

var speed:Number = 5;

this.onEnterFrame = function(){
     if(Key.isDown(Key.RIGHT)){
          bg._x-=speed;               // this will make the background move to the left, it will appear as if the char is moving to the right
          char._xscale=100;         // this will make the char 'look' to the right
     }
     if(Key.isDown(Key.LEFT)){
          bg._x+=speed;             // this will make the background move to the right, it will appear as if the char is moving to the left
          char._xscale=-100;       // this will make him 'look' to the left
     }
}

place this code directly on frame 1 of the stage.
char and bg are the names I gave to the movieclips on the stage, being the drawing of the char and the background image.

2) if the character hits the side (wall), the background 'moves'
do the following:

var speed:Number = 5;
var stage_width:Number = 300;


this.onEnterFrame = function(){
     if(Key.isDown(Key.RIGHT)){
          char._x+=speed;           // this will make the char move to the right
          char._xscale=100;         // this will make the char 'look' to the right
              if(char._x>=stage_width){
                  char._x=0;                        // put char to the beginning of the room
                  bg._x-=stage_width;            // change background
              }
     }
     if(Key.isDown(Key.LEFT)){
          char._x-=speed;           // this will make the char move to the left
          char._xscale=-100;       // this will make him 'look' to the left
              if(char._x<=0){
                  char._x=stage_width-char._width;                        // put char to the beginning of the room
                  bg._x+=stage_width;            // change background
              }
     }
}



To make it easier for you, I've made demo's, complete with fla source files.

http://psyki.be/flash/scroller_game/

Have fun!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now