corona - Shifting display groups around in a lua table -
i working on camera module game. designing work large amounts of randomly generated data. data in form of 2d chunks. labeled , referenced actual x, y coordinates. each chunk has group attached in order contain images associated it. have group contains chunks on screen ( simple simple attempt @ culling ). when player moves in direction width of chunk, current chunks need shift in table 1 element , new row ( or column ) of chunks needs loaded in edge row ( or column ). problem comes when shifting. getting error says have either removed image group or parent group. problem haven't done this. following code section having issues in ( think whole code large post @ once ):
note: @ end section removal of elements occurs. have marked asterisks.
if( changebottom == true ) = 1, newview.numviewchunksy - 1 j = 1, newview.numviewchunksx newview.imagechunktable[i][j] = newview.imagechunktable[i + 1][j] end end j = 1, newview.numviewchunksx local = newview.numviewchunksy local metax local metay if( newview.metaloadingdata.l == true ) if( ( newview.curchunk.x + ( j - 3 )*chunksize ) < newview.curmetachunk.x ) metax = 1 else metax = 2 end elseif( newview.metaloadingdata.r == true ) if( ( newview.curchunk.x + ( j - 3 )*chunksize ) > ( newview.curmetachunk.x + metachunksize*chunksize ) ) metax = 2 else metax = 1 end else metax = 1 end if( newview.metaloadingdata.t == true ) if( ( ( newview.curchunk.y + ( - 2 )*chunksize ) < newview.curmetachunk.y ) ) metay = 1 else metay = 2 end elseif( newview.metaloadingdata.b == true ) if( ( newview.curchunk.y + ( - 2 )*chunksize ) >= newview.curmetachunk.y + metachunksize*chunksize ) metay = 2 else metay = 1 end else metay = 1 end local chunk = newview.metachunktable[metay][metax].chunktable[ ( newview.curchunk.y + ( - 2 )*chunksize )/chunksize - newview.metachunktable[metay][metax].y/chunksize + 1 ][ ( newview.curchunk.x + ( j - 3 )*chunksize )/chunksize - newview.metachunktable[metay][metax].x/chunksize + 1 ] newview.imagechunktable[newview.numviewchunksy][j].displaygroup:removeself()---------- newview.imagechunktable[newview.numviewchunksy][j] = nil * newview.imagechunktable[newview.numviewchunksy][j] = imagechunk.new( chunk ) * end
edit : exact wording of error getting ( without file paths ) follows:
error: attempt remove object that's been removed stage or parent/ancestor group has been removed.
here line referenced debugger:
newview.imagechunktable[newview.numviewchunksy][j].displaygroup:removeself()
i have marked in code hyphens.
edit 2 : imagechunk module:
local imagechunk = {} local imagechunk_mt = { __index = imagechunk } function imagechunk.new( infochunk ) local chunksize = 10 local tilesize = 48 local newimagechunk = { objtable = {}, displaygroup = display.newgroup() } = 1, infochunk.numlayers newimagechunk.objtable[i] = {} j = 1, infochunk.layer[i].nummembers newimagechunk.objtable[i][j] = display.newimage( infochunk.layer[i].group[j].kind.."/"..infochunk.layer[i].group[j].subkind..".png", infochunk.layer[i].group[j].x, infochunk.layer[i].group[j].y ) newimagechunk.displaygroup:insert( newimagechunk.objtable[i][j] ) end end return setmetatable( newimagechunk, imagechunk_mt ) end return imagechunk
probably newview.numviewchunksy][j].displaygroup
same 2 or more j
. depending on when error occurs (if first shift ok second shift fails, example), newview.numviewchunksy][j] = imagechunk.new( chunk )
incorrect: maybe imagechunk.new()
returns nil or doesn't return group. update:
based on update, i'm wondering code shows call imagechunk.new
other last line. not true each j corresponds different image chunk display group: newview.imagechunktable[i][j] = newview.imagechunktable[i + 1][j]
, cause of problem.
Comments
Post a Comment