Learn Create Your Own Split Screen

Next Page

Remember we made an image variable called pipe_piece ?

We're going to tell the two halves to use that image as their image.

We can do this by "reaching inside" the MySprite object and setting the MyImg property directly (if this sounds meaningless to you, you may want to go back and review how we invented a MySprite, and how it has a place to store an image).

function add_pipe(x_pos, top_of_gap, gap_width) { // First the top pipe var top_pipe = new MySprite(); top_pipe.MyImg = pipe_piece; pipes.push(top_pipe); // Then the bottom pipe var bottom_pipe = new MySprite(); bottom_pipe.MyImg = pipe_piece; bottom_pipe.flipV = true; pipes.push(bottom_pipe ); }

We assign the pipe_piece image to each of the two MySprites we've created, but for the bottom_pipe, we also flip it so it appears the other way up.