Newbie question Add object to map

Sorry, I’m new at lime and corona, but I can’t solve this problem for a few days.
I’ve got a simple application: by tapping on the field - create new brick, by touching brick move it and position to the field cell. By touching outside brick - move map.

If I place object in Tilded and do like in tutorial “Building a Platform game with Corona and Lime”:

[code]function onPlayerLoaded(object)

player = display.newImage(object.sheet)

local layer = map:getObjectLayer(“Physics”)
layer.group:insert(player)

player.x = object.x
player.y = object.y
end
map:addObjectListener(“Player”, onPlayerLoaded) [/code]
Everything works fine except, I don’t know how to add second and more players dynamicly
If I create object without creating object it Tiled:

local brick = display.newImage("images/brick.png") brick.x = xPos brick.y = yPos local layer = map:getObjectLayer("Buildings") layer:addObject(brick) brick:addEventListener("touch", onDrag)

That object don’t save it’s position while moving the map (stays on the screen while map changes location)

My code [code]
local function onTouch(event)
if brickMove == false then
– Drag the map
map:drag(event)
end
end

local function onDrag(event)
brickMove = true
local object = event.target
lime.utils.dragObject(object, event)

if event.phase == “ended” or event.phase == “cancelled” then
tapCell = getCell(lime.utils.screenToWorldPosition(map, event))
object.x = tapCell.x * tileWidth - (tileWidth * 0.5)
object.y = tapCell.y * tileHeight - (tileHeight * 0.5)
brickMove = false
end
end

local function onTap(event)

local brick = display.newImage(“images/brick.png”)
brick.x = xPos
brick.y = yPos
local layer = map:getObjectLayer(“Buildings”)
layer:addObject(brick)
brick:addEventListener(“touch”, onDrag)
end

Runtime:addEventListener( “tap”, onTap )
Runtime:addEventListener( “touch”, onTouch )[/code]

Can you please explain me how is it better to add objects by action and place them to the map?
[import]uid: 146392 topic_id: 26015 reply_id: 326015[/import]

You might need to add a map listener after you create the brick in code. Something like:

[lua]map:getTileLayer(“Map”):addObject(brick)[/lua]

You might already have that and didn’t mention it, but that is usually necessary to identify objects. [import]uid: 135394 topic_id: 26015 reply_id: 117788[/import]