Solved

Flash Platform Game - Scrolling

Posted on 2006-11-28
1
360 Views
Last Modified: 2010-05-18
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
Comment
Question by:dh-s
1 Comment
 
LVL 5

Accepted Solution

by:
psyki_be earned 125 total points
ID: 18040466
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can't get text from a text entry 13 288
Action Script commands 3 220
Begin mp4 video on first frame 6 179
Rotating Adobe pdf document 4 321
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
Recently, I was asked to recommend a tracking system to be implemented on a clients website. As the entire site was built on flash, my first thought was to suggest custom built tracking system. However, our company at that point of time didn't h…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question