Games like this typically trigger enemy appearances and events based on how far the background has scrolled past the screen. To focus on the challenges of the project, we'll import the background itself and just add the scrolling logic to issue events that track this progress.
You should have already copied the partly completed project from the version 0
folder into your new project directory; if you haven't, do that now.
We'll start by loading the new marsh
background into the Ground
layer of the game's view, instead of the blank rectangle that the project uses by default. Open the game.lua
file and change the createScene
function to load this module as the new background, as shown in the following code snippet:
local group = self.view
self.Ground = require "level.marsh"(group)
self.Mobs = display.newGroup()
Then we adjust the scale of the background to make it fit into the width of the screen:
self.Ground = require ...