O'Reilly logo

Corona SDK HOTSHOT by Nevin Flanagan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Scrolling around a large level

The result of reducing the background to a screen-sized window is that it has to be kept placed behind whatever section of the world is currently visible in that screen.

Getting on with it

Open world.lua, if needed.

Displaying the visible background

Insert a new local function before the module function, which will set the world tiles to display the needed portion of the background:

local function alignBackground(world, ground)
end

return function (terrain, columns, rows)

First, determine which tile appears in the top-left corner of the screen:

local function alignBackground(world, ground)
  local x, y = world:contentToLocal(0, 0)
  x, y = math.floor(x / world.HSize), math.floor(y / world.VSize)
end

Next, go through each ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required