I have this wall module that I use to create walls, however, when creating them the physics bodies of the walls move, but the walls themselves don’t. They don’t move with the camera I am using, the camera works fine with all other objects.
--call in level.lua levelManager.load(levelToLoad, cameraGroup, enemyGroup) --level manager module local M = {} local wall = require "HelperModules.OtherMods.wall" local function loadLevel1(group, enemyGroup) wall.new(group, 100, 100, 40, 500, false, false) end local levels = { loadLevel1 } function M.load(levelNumber, group, enemyGroup) levels[levelNumber](group, enemyGroup) end return M --wall module local segLength = 127 local segWidth = 29 local debugEn = false local wallChunk = require "HelperModules.OtherMods.wallChunk" local bullet = require "HelperModules.GameMods.bullet" local wallM = {} function wallM.new( group, x, y, angle, length, allowEndGap, isPassive) group = group or display.currentStage angle = angle or 0 length = length or 260 -- if( length \< segLength ) then return nil, nil, nil end -- local parts = {} -- -- local numSegments = math.floor( length/segLength ) local remaining = length - (numSegments \* segLength) -- local numGaps = (allowEndGap==true) and numSegments or numSegments-1 local gapLen = 0 if( numGaps \> 0 ) then gapLen = remaining/numGaps end -- local vec = ssk.math2d.angle2Vector( angle, true ) vec = ssk.math2d.scale( vec, segLength + gapLen ) table.dump(vec) -- for i = 1, numSegments do local seg = wallChunk.new(group, x, y, angle, 0, isPassive) seg.rotation = angle - 90 -- parts[#parts+1] = seg -- if( debugEn ) then local tmp = display.newCircle( group, x, y, 5 ) tmp:setFillColor(unpack(\_R\_)) tmp.alpha = 0.75 end -- x = x + vec.x y = y + vec.y physics.addBody(seg, "static") end return parts, x, y end return wallM --wallChunk module local M = {} local bullet = require "HelperModules.GameMods.bullet" local id = 0 --non-passive walls react to player collision --passive walls do not react to any collisions local function fiveSpread(obj) local group = obj.parent local x = obj.x local y = obj.y bullet.new(group, x, y, obj.rotation - 30, 500, 4) bullet.new(group, x, y, obj.rotation - 15, 500, 4) bullet.new(group, x, y, obj.rotation, 500, 4) bullet.new(group, x, y, obj.rotation + 15, 500, 4) bullet.new(group, x, y, obj.rotation + 30, 500, 4) end function wallCollision(self, event) if event.phase == "began" then if self.isPassive then return end if event.other.id == "char" and self.active then threeSpread(self) self.active = false timer.performWithDelay(1500, function() self.active = true end) end end end function M.new(group, x, y, angle, myId, isPassive) local wall = display.newImageRect("Assets/Sprite/Tile1.png", 149, 34) wall.x = x wall.y = y wall.rotation = angle id = myId wall.isPassive = isPassive wall.active = true physics.addBody(wall, "static") wall.collision = wallCollision wall:addEventListener("collision") return wall end return M
Sorry that it’s a lot of code, but I can’t seem to narrow where this problem is so I added the entire flow of the modules and calls.