Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Moving through space" #17

Open
eclipsate opened this issue Nov 23, 2017 · 1 comment
Open

"Moving through space" #17

eclipsate opened this issue Nov 23, 2017 · 1 comment

Comments

@eclipsate
Copy link

I'm trying to move my dog through space i.e. make the grass background move forward to give the illusion of the whole scene progressing.

I tried building off of your example code, but can't figure out the code needed to move through space.

Then I tried using this flappy bird game as a base. The sky image does progress forward like I want, but only for a few seconds. It does not go the same speed as my dog and lags behind. I have no idea why or how to fix that.

@chjno
Copy link
Owner

chjno commented Nov 26, 2017

You're going to want to draw the image with image() instead of using bg() because image() allows you to change the coordinates of the image. You could try something like:

var bgX = 0;

function draw() {
  // background(bgImg);
  image(bgImg, bgX, 0);
  bgX -= 1;
  if (bgX < -width){
    bgX = 0;
  }
}

That's the most straightforward way I can think of. You might want to play around with the bgX increment amount to adjust the speed and the if statement to adjust when the image resets to 0,0. You could also have two images drawn next to each other and once one goes of the screen you can place it to the right of the next image if that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants