chjno / MEDP349-Fall17

MEDP 349 Physical Computing, Hunter College, Fall 2017
3 stars 3 forks source link

continuous scrolling background image #19

Open chjno opened 6 years ago

chjno commented 6 years ago

Posting from email @eclipsate

Hi Chino,

I remember you gave me a suggestion for how to make a smoother transition for the background in my game. This is the code for my background, I think I said I should have the same image twice so it doesn’t skip when it rotates through? How would I do that?

image(bgImg, bgX, 0); bgX -= 2; if (bgX < -width) { bgX = 0; }

Thanks!

chjno commented 6 years ago

Say I'm using this image for my background:

First, I'll draw the same image twice side by side - one at (0,0) and one at (width,0). Then I'll have them both scroll at the same speed. Once the image on the left leaves the screen completely, I can have it jump to the right of the image that is currently on the screen.

http://alpha.editor.p5js.org/chjno/sketches/ByZlypKWM