Hi everyone,
I'm very new to AS 3.0 (only been working w/ it for a week), but very well versed in animating using Flash. I'm interested in getting into creating games using AS 3.0, and so far I've been finding it a lot of fun.
Many apologies if a solution to my issue has been brought up before, but this is what I'm attempting to do:
- I have a character that stands in the center of the screen.
- I have a background graphic of mountains that is as wide as the screen is.
- When the user presses the right or left arrow keys, the character should go into a walk animation, and the background graphic should move along the x axis accordingly. So far, so good. The key bindings work correctly, and the background graphic indeed moves accordingly.
PROBLEM:
I've read some online tutorials that detailed how you can create two instances of the same background graphic, and put them side-by-side using actionscript. I used that code, but it's not working; they are actually spawning *on top of one another*.
this is the code I used:
ActionScript Code:
var bg1:BG1;
var bg2:BG1;
bg1 = new BG1();
bg2 = new BG1();
bg1.x = 0;
bg2.x = bg1.width;
Is there something wrong with how I wrote that? It seems like .width is not working the way I imagined it to. What I would like to do is have the code put instances of the BG graphics beside itself on the stage, to give the illusion of one continuously scrolling background.
this is the code for that scrolling:
ActionScript Code:
public function tileBG(e:Event):void
{
bg1.x += xScrollSpeed;
bg2.x += xScrollSpeed;
if ( bg1.x < -bg1.width )
{
bg1.x = bg1.width;
}
else if ( bg2.x < -bg2.width )
{
bg2.x = bg2.width;
}
}
Any ideas on what I'm doing wrong? It's had me stumped for over a week!