spawn object where touched but only when btn is pressed

Hey guys I have a question about cloning an actor on button touch and the actor will be put where you touch. I have tried many things but I am not quite getting it.(kinda like plantsVSzombies)

--I want the cloned actor to have the same functions as the first actor local composer = require( "composer" ) local scene = composer.newScene() -- ----------------------------------------------------------------------------------------------------------------- -- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called. -- ----------------------------------------------------------------------------------------------------------------- -- local forward references should go here -- ------------------------------------------------------------------------------- -- "scene:create()" function scene:create( event ) local physics = require("physics") local sceneGroup = self.view physics.start() local isitselectedcannon = false local ground = display.newRect(200,200,650,500) ground:setFillColor(0,255,0) local deathpoint1 = display.newRect(10,50,30,30) --main cannon is the object I want to clone local maincannon = display.newRect(math.random(20,400),math.random(0,300),30,30) local numberSmiles = 1 --local variable; amount can be changed local money = 100 local cannonbuy = display.newText("Buy Cannon",360,30,native.systemFont,25) local acannonx = maincannon.x print(acannonx) local function spawnSmiles() for i=1,numberSmiles do local zombie = display.newRect(400,50,50,50) physics.addBody(zombie,"dynamic") local zomhlth = 1 -- smile:setReferencePoint(display.CenterReferencePoint); --not necessary; center is default zombie.x = 400; zombie.y = 50; transition.to( zombie, { time=10000, x=deathpoint1.x , y=deathpoint1.y, onComplete=clearSmile } ); if zombie.x \> maincannon.x then print("shoot!!") local function spawnbullets( event ) local bullet = display.newRect(maincannon.x,maincannon.y,40,20) physics.addBody(bullet,"static") transition.to( bullet, { time=3000, x=zombie.x , y=zombie.y } ); local function collision( event ) if event.phase==("began") then bullet:removeSelf() zombie:removeSelf() end end bullet:addEventListener("collision",collision) end spawnbullets() end end end timer.performWithDelay(1000,spawnbullets,0) timer.performWithDelay( 5000, spawnSmiles, 0 ) --fire every 10 seconds function maincannon:touch( event ) if event.phase == "began" then self.markX = self.x -- store x location of object self.markY = self.y -- store y location of object elseif event.phase == "moved" then local x = (event.x - event.xStart) + self.markX local y = (event.y - event.yStart) + self.markY self.x, self.y = x, y -- move object based on calculations above end return true end -- make 'myObject' listen for touch events maincannon:addEventListener( "touch", myObject ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is still off screen (but is about to come on screen). elseif ( phase == "did" ) then -- Called when the scene is now on screen. -- Insert code here to make the scene come alive. -- Example: start timers, begin animation, play audio, etc. end end -- "scene:hide()" function scene:hide( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "will" ) then -- Called when the scene is on screen (but is about to go off screen). -- Insert code here to "pause" the scene. -- Example: stop timers, stop animation, stop audio, etc. elseif ( phase == "did" ) then -- Called immediately after scene goes off screen. end end -- "scene:destroy()" function scene:destroy( event ) local sceneGroup = self.view -- Called prior to the removal of scene's view ("sceneGroup"). -- Insert code here to clean up the scene. -- Example: remove display objects, save state, etc. end -- ------------------------------------------------------------------------------- -- Listener setup scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) scene:addEventListener( "hide", scene ) scene:addEventListener( "destroy", scene ) -- ------------------------------------------------------------------------------- return scene