Solved

Flash Platform Game - Scrolling

Posted on 2006-11-28
1
334 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
Comment Utility
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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
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…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

743 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

15 Experts available now in Live!

Get 1:1 Help Now