Solved

Flash Platform Game - Scrolling

Posted on 2006-11-28
1
346 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Embedded Video Download (Flash) 3 1,150
How  to reduce the .AVI file size of 90GB 4 342
bandwidth 5 67
Shouldn't i be able to use an old win xp machine as an internet radio? 7 120
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now