Hello! Here’s the gist of my issue: I have three display groups - self.Backdrop, self.Tile, self.Creatures - respectively they are inserted into another display group called self.
According to readings on Corona API and posts on display groups, the order in which the display objects appear follows the order in which the display groups are inserted into the scene group. However, that doesn’t seem to be the case in my program.
As mentioned, I have inserted self.Backdrop first, self.Tile second, then self.Creatures third. So, the images should stack with self.Backdrop being in the background, self.Tile on the top of self.Backdrop , then self.Creatures on top of all the images. But, that’s not what I’m getting. self.Creatures appear in between self.Backdrop and self.Tile. I’d like to know why so I can fix this issue.
I also confirmed whether the objects were inserted in the correct order by outputting the names of all the table elements in the self group table.
The table numbers for each display group are the following:
self.Backdrop: 0DE56658
self.Scroll: 0DE56710
self.Creatures:0DE56B20
The elements of the self group table appear in the following order: 0DE56658, 0DE56710, 0DE56B20. So, essentially the display groups should appear in the order that corresponds the order in which display groups are inserted in to self group. But, I don’t know why that isn’t the case.
Here’s a snippet of the code:
return function(options) local self = display.newGroup() if options.Backdrop then self.Backdrop = display.newImage(self, options.Backdrop, w/2, 0) self.Backdrop.anchorY = 0 end local tilePath = options.Tile if tilePath then --self.Scroll = display.newGroup(); self:insert(self.Scroll) function self:StartBackground() local tile = display.newImage(tilePath, display.contentWidth, 0) tile.anchorX = 0 tile.anchorY = 1 tile.Shift = transition.to(tile, {time = 4000, delta = true, onComplete = function(...) return self:StartBackground() end; x = -2\*display.contentWidth, y = 2\*display.contentHeight}) end end self.Inhabitants = options.Inhabitants self.Scroll = display.newGroup(); self:insert(self.Scroll) self.Creatures = display.newGroup(); self:insert(self.Creatures) -- Event Listening Function function self:Game(event) function self:Game(event) if event.action == 'start' then start(self, event.duration) elseif event.action == 'stop' then stop(self) end end local function retransmit(...) self:dispatchEvent(...) end function self:remove(event) self:dispatchEvent{name = 'Despawn'; unit = event.target} end function self:Spawn(info) local newSpawn = self.Inhabitants[info.kind](self.Creatures, info.x, info.y, unpack(info)) newSpawn:addEventListener('Death', retransmit) newSpawn:addEventListener('remove', self) end return self end