So I’ve been trying to go through learningcorona.com and stumbled upon “How to spawn objects the right way” at
http://blog.anscamobile.com/2011/09/how-to-spawn-objects-—-the-right-way/
I feel like I’m understanding it pretty well and that it’s creating the objects properly as confirmed by the function
for i = 1, #spawnTable do
print(spawnTable[i].myName)
end
,but how to I actually change where the objects appear on screen? As you can see, I tried passing in object.x and object.y parameters, but the objects never seem to draw on screen. Any help?
[code]
–Function to spawn an object
local function spawn(params)
local object = display.newImage(params.image)
–Set the objects table to a table passed in by parameters
object.objTable = params.objTable
–Automatically set the table index to be inserted into the next available table index
object.index = #object.objTable + 1
–Give the object a custom name
object.name = “bouncer” … object.index
–If the object should have a body create it, else dont.
if params.hasBody then
–Allow physics parameters to be passed by parameters:
object.density = params.density or 0
object.friction = params.friction or 0
object.bounce = params.bounce or 0
object.isSensor = params.isSensor or false
object.bodyType = params.bodyType or “static”
physics.addBody(object, object.bodyType, {density = object.density, friction = object.friction, bounce = object.bounce, isSensor = object.isSensor})
end
–The objects group
object.group = params.group or nil
–If the function call has a parameter named group then insert it into the specified group
object.group:insert(object)
–Insert the object into the table at the specified index
object.objTable[object.index] = object
object.x = params.x or 50
object.y = params.y or 50
return object
end
–Create a table to hold our spawns
local spawnTable = {}
–Create 50 spawns
for i = 1, 50 do
local spawns = spawn(
{
image = “images/bouncer.png”,
objTable = spawnTable,
hasBody = true,
isSensor = true,
group = localGroup,
x = 100,
y = 100
}
)
end
[/code] [import]uid: 131400 topic_id: 23655 reply_id: 323655[/import]

[import]uid: 131400 topic_id: 23655 reply_id: 95254[/import]