Solved

Flash Platform Game - Scrolling

Posted on 2006-11-28
1
375 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
I have found that much of my time doing support ends up being a constant repetition of the same steps to different people.  Early on I stated using web pages with Frequently Asked Questions (FAQs) to alleviate most of the burden.  Sometimes this jus…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to how to record live broadcast.

728 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