Dusk Engine: Parallax scrolling "procedure"?

I wasn’t sure where to put this as it isn’t a Corona SDK question directly.

Dusk accepts a custom property in a layer of a Tiled map as the “rate” at which a layer will scroll.

xParallax and yParallax.  

If the camera is locked to the player object it’s defacto rate is apparently the control of “1.0” regardless of how fast it’s actually moving.

So I stacked several image layers in my Tiled map and set the xParallax scrolling factor to various levels and it works great.  Here’s the problem I’m facing.

I don’t see a procedure or “way to handle” the infinite scrolling background.  The images will roll off screen as I travel across the X axis if I travel in a direction and roll back on screen if I travel in the opposite direction.  It makes perfect sense.

In “conventional scrolling” that isn’t physics based from the examples I’ve seen, you stack two (or more) images side by side (or vertically) and when they are “off screen” in whatever opposite direction the player moves, they then get translated to the opposite side off screen and scroll in again.

I tried adding an additional image layer with an offset of the x axis equal to the width of the image and that image doesn’t draw at all.  EDIT:  The images are there but the Tiled internal layer property “Horizontal Offset” is not being looked at in Dusk, so it’s stacking all the image layers  on top of each other.

It doesn’t seem practical to have an image layer with an image that’s the width of the level either.

Ideas or suggestions?

Ok I solved it.  Dusk’s core lua files has one called “imagelayer.lua”.  It deals with adding image layers to the map.  I had to modify it.

The original function:

function lib\_imagelayer.createLayer(map, data, dirTree) local props = getProperties(data.properties or {}, "image", true) local layer = display\_newGroup() layer.props = {} layer.\_layerType = "image" local imageDir, filename = getDirectory(dirTree, data.image) layer.image = display\_newImage(layer, imageDir .. filename) layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5), data.y + (layer.image.height \* 0.5) ------------------------------------------------------------------------------ -- Destroy Layer ------------------------------------------------------------------------------ function layer.destroy() display.remove(layer) layer = nil end ------------------------------------------------------------------------------ -- Finish Up ------------------------------------------------------------------------------ addProperties(props, "props", layer.props) addProperties(props, "layer", layer) return layer end

Tiled properties offsetx and offsety in the JSON (but called Horizontal Offset and Vertical Offset in Tiled layer properties) were not being evaluated even though they were in the “data” table.

Here is the modified function:

function lib\_imagelayer.createLayer(map, data, dirTree) local props = getProperties(data.properties or {}, "image", true) local layer = display\_newGroup() layer.props = {} layer.\_layerType = "image" local imageDir, filename = getDirectory(dirTree, data.image) layer.image = display\_newImage(layer, imageDir .. filename) -- Adding the code to look at previously ignored properties local tempOffsetX if(data.offsetx == nil ) then tempOffsetX = 0 else tempOffsetX = data.offsetx end local tempOffsetY if(data.offsety == nil ) then tempOffsetY = 0 else tempOffsetY = data.offsety end -- end of new stuff layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5) + tempOffsetX, data.y + (layer.image.height \* 0.5) + tempOffsetY --layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5), data.y + (layer.image.height \* 0.5) ------------------------------------------------------------------------------ -- Destroy Layer ------------------------------------------------------------------------------ function layer.destroy() display.remove(layer) layer = nil end ------------------------------------------------------------------------------ -- Finish Up ------------------------------------------------------------------------------ addProperties(props, "props", layer.props) addProperties(props, "layer", layer) return layer end

Ok I solved it.  Dusk’s core lua files has one called “imagelayer.lua”.  It deals with adding image layers to the map.  I had to modify it.

The original function:

function lib\_imagelayer.createLayer(map, data, dirTree) local props = getProperties(data.properties or {}, "image", true) local layer = display\_newGroup() layer.props = {} layer.\_layerType = "image" local imageDir, filename = getDirectory(dirTree, data.image) layer.image = display\_newImage(layer, imageDir .. filename) layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5), data.y + (layer.image.height \* 0.5) ------------------------------------------------------------------------------ -- Destroy Layer ------------------------------------------------------------------------------ function layer.destroy() display.remove(layer) layer = nil end ------------------------------------------------------------------------------ -- Finish Up ------------------------------------------------------------------------------ addProperties(props, "props", layer.props) addProperties(props, "layer", layer) return layer end

Tiled properties offsetx and offsety in the JSON (but called Horizontal Offset and Vertical Offset in Tiled layer properties) were not being evaluated even though they were in the “data” table.

Here is the modified function:

function lib\_imagelayer.createLayer(map, data, dirTree) local props = getProperties(data.properties or {}, "image", true) local layer = display\_newGroup() layer.props = {} layer.\_layerType = "image" local imageDir, filename = getDirectory(dirTree, data.image) layer.image = display\_newImage(layer, imageDir .. filename) -- Adding the code to look at previously ignored properties local tempOffsetX if(data.offsetx == nil ) then tempOffsetX = 0 else tempOffsetX = data.offsetx end local tempOffsetY if(data.offsety == nil ) then tempOffsetY = 0 else tempOffsetY = data.offsety end -- end of new stuff layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5) + tempOffsetX, data.y + (layer.image.height \* 0.5) + tempOffsetY --layer.image.x, layer.image.y = data.x + (layer.image.width \* 0.5), data.y + (layer.image.height \* 0.5) ------------------------------------------------------------------------------ -- Destroy Layer ------------------------------------------------------------------------------ function layer.destroy() display.remove(layer) layer = nil end ------------------------------------------------------------------------------ -- Finish Up ------------------------------------------------------------------------------ addProperties(props, "props", layer.props) addProperties(props, "layer", layer) return layer end