AI Tutorial - Moving the Background
 
Another popular thing to have in scrollers is backgrounds that moves at different rates. Also in this game we will make it so the video game switch between day and night about every minute. Make a new script file and name it Background.cs. Add the following code to it.
Next Page
Previous Page
The code above simply moves the camera to the object it is mounted to. It caps out at the MinX and the MaxX. If we tested this code we couldn't tell if it was working because the background is black so let's add the background.
if (!isObject(BackgroundBehavior))
{
%template =
new BehaviorTemplate(BackgroundBehavior);
  
%template.friendlyName =
"Background Scroller";
%template.behaviorType =
"Camera";
%template.description  =
"Scrolls the background by the position of the camera";
  
%template.addBehaviorField(Scroll,
"Amount to scroll (0-1)", float, 0.5);
%template.addBehaviorField(DayNightBool,
"Affected by time", bool, 0);
}

function BackgroundBehavior::onBehaviorAdd(%
this)
{
%
this.owner.enableUpdateCallback();
}

function BackgroundBehavior::onBehaviorRemove(%
this)
{
if (!isObject(moveMap))
return;

%
this.owner.disableUpdateCallback();
}

function BackgroundBehavior::onUpdate(%
this)
{
%position = sceneWindow2D.getCurrentCameraPosition();
%
this.owner.setPositionX(%position * %this.Scroll);

//if affected by time fade to invisible when time gets coloser to 0
if(%this.DayNightBool)
{
%
this.owner.setBlendAlpha($Time/1000);
}}