How to draw scrolling background?

How do I make a scrolling background in Flash 8 that follows an object controlled by the mouse?

  • If you don't get what I mean, I'm talking about something like the background in this game; http://www.kongregate.com/games/Pacthesis/chrono-days-sim-date (To find what I'm talking about, click "skip intro" at the beginning of the game, then click "leave" twice to go outside).

  • Answer:

    What's happening here is that the background's X position is being dynamically controlled based on the position of the mouse within the window (I'm sure you already knew that). The closer the object is to one side or the other, the slower the background scrolls until it reaches the extreme edge. The actionscript would go something like this (likely needs debugging to get it to work): onEnterframe() { var mouseXpos = _root._xmouse; var bg_width = bg_movieClip._width; var stage_width = stage.width; var bgPosRatio =mouseXpos/stage_width; bgMovieClipInstnceName._x = bgPosRatio*(bg_width - stage_width); } This doesn't give it the speed/up slow down effect but will scroll across the background movie clip at a constant rate.

Ahil at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.