Skip to content

Instantly share code, notes, and snippets.

@jakevsrobots
Created August 23, 2010 22:19
Show Gist options
  • Save jakevsrobots/546468 to your computer and use it in GitHub Desktop.
Save jakevsrobots/546468 to your computer and use it in GitHub Desktop.
package beulah {
import org.flixel.*;
public class Background extends FlxGroup {
private var cloudsOne:FlxSprite;
private var cloudsTwo:FlxSprite;
private var landOne:FlxSprite;
private var landTwo:FlxSprite;
private var screenTestPoint:FlxPoint;
private var season:String;
public function Background():void {
super();
season = 'spring';
landOne = new FlxSprite(0,FlxG.height / 4,Main.library.getAsset(season + 'LandBackground'));
landOne.scrollFactor.x = 0.125;
landOne.scrollFactor.y = 0.125;
landTwo = new FlxSprite(0,FlxG.height / 4,Main.library.getAsset(season + 'LandBackground'));
landTwo.scrollFactor.x = 0.125;
landTwo.scrollFactor.y = 0.125;
landTwo.x = landOne.x + landOne.width;
cloudsOne = new FlxSprite(0,0,Main.library.getAsset('skyBackground'));
cloudsOne.scrollFactor.x = 0.05;
cloudsOne.scrollFactor.y = 0.05;
cloudsTwo = new FlxSprite(0,0,Main.library.getAsset('skyBackground'));
cloudsTwo.scrollFactor.x = 0.05;
cloudsTwo.scrollFactor.y = 0.05;
cloudsTwo.x = cloudsOne.x + cloudsOne.width;
var backgroundOverlay:FlxSprite = new FlxSprite(0, 0);
backgroundOverlay.createGraphic(FlxG.width, FlxG.height, 0xffffffff);
backgroundOverlay.scrollFactor.x = backgroundOverlay.scrollFactor.y = 0;
backgroundOverlay.alpha = 0.3;
add(cloudsOne);
add(cloudsTwo);
add(landOne);
add(landTwo);
add(backgroundOverlay);
screenTestPoint = new FlxPoint;
}
public function setSeason(season:String):void {
this.season = season;
landOne.loadGraphic(Main.library.getAsset(season + 'LandBackground'));
landTwo.loadGraphic(Main.library.getAsset(season + 'LandBackground'));
}
override public function update():void {
super.update();
cloudsOne.getScreenXY(screenTestPoint);
if(screenTestPoint.x < 0 && cloudsTwo.x < cloudsOne.x) {
cloudsTwo.x = cloudsOne.x + cloudsOne.width;
}
cloudsTwo.getScreenXY(screenTestPoint);
if(screenTestPoint.x < 0 && cloudsOne.x < cloudsTwo.x) {
cloudsOne.x = cloudsTwo.x + cloudsTwo.width;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment