Code: Parallax Scrolling

All talk relating to Edward, the Flash platform game engine. (Forum is now locked)

Code: Parallax Scrolling

Postby thatjoshguy » Mon Apr 27, 2009 3:54 pm

I finally figured out how to add parallax scrolling to your levels. It isn't perfect, but it works!

Add this to the top of the actionscript on the initialization frame, right under "var mcLevel:MovieClip;":

Code: Select all
var parscroll:MovieClip;


Scroll down until you see this section:

Code: Select all
//############################# Level Positioning ################################
   //## Center player in screen
   if (scrollingMode){
      mcLevel.x = -mcLevel.mcPlayer.x + (STAGEWIDTH / 2);
      mcLevel.y = -mcLevel.mcPlayer.y + (STAGEHEIGHT / 2);
   }


change it to this:

Code: Select all
//############################# Level Positioning ################################
   //## Center player in screen
   if (scrollingMode){
      mcLevel.x = -mcLevel.mcPlayer.x + (STAGEWIDTH / 2);
      mcLevel.y = -mcLevel.mcPlayer.y + (STAGEHEIGHT / 2);
   //# parralax Scrolling
      parscroll.x = -(mcLevel.mcPlayer.x*0.5);
      parscroll.y = -(mcLevel.mcPlayer.y*0.5);
   }


okay, on the levels where you want a parallax scrolling object, create a new symbol ON THE MAIN TIMELINE BELOW THE LEVEL MOVIECLIP. I put mine on a seperate layer. Inside of this movieclip, draw the background that will be scrolling. make it a little larger than the level.

On the first frame of this movieclip, add the following actionscript:

Code: Select all
MovieClip(parent).parscroll = this


Save, and test your movie. It may take some tweaking to get the parallax objects origin in the right place, but it works! Plus, you can duplicate this movieclip behind another level later on, with totally different graphics.

Maybe GirlFlash can add this (in a prettier fashion) to the next release? The scrollspeed could be set at the initialization frame (or manually by changing the code above from 0.5 to whatever)
thatjoshguy
Power Player
 
Posts: 39
Joined: Fri Apr 17, 2009 5:58 pm

Re: Code: Parallax Scrolling

Postby SophieH » Mon Apr 27, 2009 5:49 pm

thats actually pretty much a perfect implementation, you could also just as easily put the parralax MC *over* the level, set the speed to be something like 1.5 and have foreground stuff :D

I'll definately play around with it with an eye to include it in the next release. props on a very simple and effective mod :bounce:
User avatar
SophieH
Site Admin
 
Posts: 76
Joined: Fri Aug 08, 2008 8:01 pm
Location: UK - Europe

Re: Code: Parallax Scrolling

Postby thatjoshguy » Mon Apr 27, 2009 8:31 pm

Aww now see, I was gonna keep the foreground part my little secret... I can't tell everyone ALL of my ideas!

BTW, how do you upload games/samples onto the wiki? If you wanted to make a tutorials section, I'd be more than happy to contribute. I'm having a blast with this engine!
thatjoshguy
Power Player
 
Posts: 39
Joined: Fri Apr 17, 2009 5:58 pm

Re: Code: Parallax Scrolling

Postby TaiMySho3 » Mon Apr 27, 2009 9:11 pm

Not to be a noob and all but what is parallax scrolling?
User avatar
TaiMySho3
Power Player
 
Posts: 32
Joined: Mon Mar 30, 2009 3:13 am
Location: Cali

Re: Code: Parallax Scrolling

Postby austino » Mon Apr 27, 2009 10:13 pm

TaiMySho3 wrote:Not to be a noob and all but what is parallax scrolling?

It's where there are multiple scrolling backgrounds at different speeds.
austino
Player
 
Posts: 15
Joined: Fri Apr 24, 2009 9:24 pm

Re: Code: Parallax Scrolling

Postby thatjoshguy » Mon Apr 27, 2009 10:19 pm

for an example, check out http://www.ironwookiearcade.com/test/ for a demo of my game being made with the edward engine. Not a lot to it as I've jsut been experiementing and developing a visual style, but the second area does use my parallax scrolling code. It's a subtle effect, but it adds a lot of depth.
thatjoshguy
Power Player
 
Posts: 39
Joined: Fri Apr 17, 2009 5:58 pm

Re: Code: Parallax Scrolling

Postby TaiMySho3 » Tue Apr 28, 2009 1:22 am

oh wow thats pretty cool, it really adds some depth to it making it more awesome, thanks for explaining it
User avatar
TaiMySho3
Power Player
 
Posts: 32
Joined: Mon Mar 30, 2009 3:13 am
Location: Cali

Re: Code: Parallax Scrolling

Postby SophieH » Tue Apr 28, 2009 2:27 am

first of all, to upload a file to the wiki there is an upload file link in the toolbox on the lefthand side of the screen, underneath the search box.
once you have the file to embed it you can copy the source of one of the example pages and use it as a template :)

as for your your example its looking very good indeed, and its totally reminded me I can affored AYIM now my last loan came in! :DD
User avatar
SophieH
Site Admin
 
Posts: 76
Joined: Fri Aug 08, 2008 8:01 pm
Location: UK - Europe


Return to Edward Topics

Who is online

Users browsing this forum: No registered users and 0 guests

cron