Hi Corona,
I recently started to learn how to spawn objects on Corona and setting the parameters. I was able to set the parameters for x and y for one spawn.
What I would like to do is set the y coordinate 5 pixels after the object that was spawned before?
For example:
object 1 spawns at x=0 and y=5
object 2 should spawn 5 pixels from the x and y of object 1
and so on…
Here is my code. (Also I am still learning to understand tables.) I’ve researched a lot about spawns and I get a lot of random spawns, but I want specific spawns. All help is greatly appreciated and any problems you see with the code will also help a lot.
Keep in mind “steps” is the “object” I want to spawn.
Thanks in advance
--Function to spawn an object local function spawn(params) local steps = display.newImage(params.image) --Set the objects table to a table passed in by parameters steps.objTable = params.objTable --Automatically set the table index to be inserted into the next available table index steps.index = #steps.objTable + 1 --Give the object a custom name steps.myName = "Object : " .. steps.index --If the object should have a body create it, else dont. if params.hasBody then --Allow physics parameters to be passed by parameters: steps.anchorX = params.anchorX or 0 steps.anchorY = params.anchorY or 0 steps.x = params.x or 0 steps.y = params.y or 0 steps.objType = params.objType steps.camera= params.camera steps.xScale = params.xScale or 1 steps.yScale = params.yScale or 1 steps.shape = params.shape or 0 steps.density = params.density or 0 steps.friction = params.friction or 0 steps.bounce = params.bounce or 0 steps.isSensor = params.isSensor or false steps.bodyType = params.bodyType or "dynamic" physics.addBody(steps, steps.bodyType, {density = steps.density, friction = steps.friction, bounce = steps.bounce, shape= steps.shape, isSensor = steps.isSensor}) end --The objects group steps.group = params.group or nil --If the function call has a parameter named group then insert it into the specified group steps.group:insert(steps) --Insert the object into the table at the specified index steps.objTable[steps.index] = steps return steps end local localGroup = display.newGroup() --Create a table to hold our spawns local spawnTable = {} --Create 2 spawns for i = 1,2 do local spawns = spawn( { image = "Steps.png", objTable = spawnTable, hasBody = true, friction = 0.2, shape={-16.5,-16.5, 16.5,-16.5, 16.5,16.5, -16.5,16.5}, bodyType = "static", objType = "ground", anchorX = 0.5, anchorY = 0.5, x=17, y= 5, xScale = 0.48, yScale = 0.48, group = localGroup, } ) camera:add(spawnTable[i], 1) end