Basically, you want to check if the character is off the screen like so:
Function SpriteOffScreen( SpriteID as Integer )
If Sprite X( SpriteID ) < 0 or Sprite X( SpriteID ) > Screen Width( ) or Sprite Y( SpriteID ) < 0 or Sprite Y( SpriteID ) > Screen Height( )
ExitFunction 1
EndIf
EndFunction 0
Once you know that it's off the screen you can change the background accordingly by changing the background sprite's image. However you also need to know if it's above the screen, below it, to the right of it or to the left of it, so here's what we'd do:
If SpriteOffScreen( Character ) = 1
If Sprite X( Character ) < 0
Set Sprite Image Background, LeftImage
EndIf
EndIf
That should do it.