# Mario game help! Move background screen when image is moved?

**URL:** https://discourse.processing.org/t/mario-game-help-move-background-screen-when-image-is-moved/659
**Category:** Coding Questions
**Created:** [June 3, 2018, 12:48am UTC](https://discourse.processing.org/t/mario-game-help-move-background-screen-when-image-is-moved/659 "2018-06-03T00:48:45Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [June 3, 2018, 5:34pm UTC](https://discourse.processing.org/t/mario-game-help-move-background-screen-when-image-is-moved/659/4 "2018-06-03T17:34:46Z")

</div>

No! You can certainly have a background image that is larger than your sketch! I took a bit of time to code you a working example:

```auto
float background_x_offset;
float mario_x_position;
float mario_y_position;
PImage bg;

void setup(){
  size(200,200);
  spoofBackgroundImage();
background_x_offset = 0;
mario_x_position = width/2;
}

void draw(){
  background(0);
  if( kd[0] ) mario_x_position--;
  if( kd[1] ) mario_x_position++;
  
  if( mario_x_position > 3*width/4 && background_x_offset < 600 ){
    mario_x_position--;
    background_x_offset++;
  }
  mario_x_position = constrain(mario_x_position,10,190);
  image(bg, -background_x_offset,0 );
  fill(255,0,0);
  ellipse(mario_x_position,170,20,20);
  fill(255);
  ellipse(mario_x_position,170,10,10);
  
}
  
void keyPressed(){
  k(true);
}

void keyReleased(){
  k(false);
}
 
int[] ks = {LEFT, RIGHT};
boolean[] kd = {false,false};
 
void k(boolean b){
 for( int i = 0; i < ks.length; i++){
   if( ks[i] == keyCode ) kd[i] = b;
 }
}
  
void spoofBackgroundImage(){
  PGraphics pg = createGraphics(800,200);
  pg.beginDraw();
  pg.background(100,100,200);
  pg.noStroke();
  pg.fill(255);
  for( int i = 0; i < 20; i++){
    pg.ellipse(random(800), random(200),30,20);
  }
  pg.stroke(0);
  for( int i = 0; i < 40; i++){
    pg.fill(255,5*i,100);
    pg.rect(20*i,180,20,20);
  }
  pg.endDraw();
  bg = pg.get();
}

```

---

_[View the full topic](https://discourse.processing.org/t/mario-game-help-move-background-screen-when-image-is-moved/659)._
