I have an error that I can't seem to work around. I have tried to re-structure this code a few different ways, but I am missing something fundamental.
I have also tried to read up on if else statements, and switches to look for other options.
The player begins in the 'Start' screen. If he moves far enough left, the scene transitions to 'leftScene'. He is moved to the right side of the screen, and the BG changes to make it appear he has moved.
function sceneTransition(e:Event):void{
if (player.x <= -10){
if (mainBG.FrameLabel = 'Start'){
player.x = 650;
mainBG.gotoAndPlay('leftScene');
}
else if (mainBG.FrameLabel = 'rightScene'){
player.x = 650;
mainBG.gotoAndPlay('Start');
}
}
else if (player.x >= 670){
if (mainBG.FrameLabel = 'Start'){
player.x = 10;
mainBG.gotoAndPlay('rightScene');
}
else if (mainBG.FrameLabel = 'leftScene'){
player.x = 10;
mainBG.gotoAndPlay('Start');
}
}
}
As is, he can walk to 'leftScene', but when he tried to return to 'Start', it skips ahead to 'rightScene'. Then if he does left again, it skips 'Start' once more, and goes straight to 'leftScene'.
I think I know the problem. But am not sure how to fix it. I think his co-ordinates get checked by all segments of the code simultaneously. So in that exact instance he satisfies the code to move him to 'Start' and to 'rightScene'. Because of this, 'Start' gets skipped every time.
How can I avoid this?
Thank you!
GAH!