I placed the following code inside a ButtonListener, but the two objects I have being spawned converge with each other instead of in the center of the screen. I basically just want both matching objects to meet at the center of the screen regardless of which of the two you tap on. I’m probably missing something really simple. Any idea what though?
--ButtonListener for Matching Group local buttonListener = function( event ) if event.numTaps == 1 then playSFX(audiomatchsound) local group = matchgroup local oldVector = group.rotation local newVector = 0 --make matching objects explode in center of screen using sparkle local px = centerX local py = centerY local function sparkleExplode(Obj) display.remove(Obj) Obj = nil transition.cancel ( group.trans ) --How about a little poof to boot local pop = display.newCircle(levelGroup, px, py, math.random(1,2)) local function DestroyPop(Obj) display.remove(Obj) Obj = nil end transition.to(pop, {time=400, alpha = 0, onComplete=DestroyPop}) --end of extra poof code ExplodeStyleEmitter(px, py) timer.performWithDelay(1000, placeitems, 1) if matchgroup ~= nil then matchgroup:removeSelf(1) matchgroup = nil end if nonMatchImageHolder ~= nil then --Remove display table of nonmatch items for key,obj in pairs(nonMatchImageHolder) do obj:removeSelf() obj = nil end end end --send object to center of screen group:toFront() physics.pause() local px = display.contentWidth/2 local py = display.contentHeight/2 item1.trans = transition.to( item1, {time=500, x = px, y = py, onComplete=sparkleExplode} ) item2.trans = transition.to( item2, {time=500, x = px, y = py, onComplete=sparkleExplode} ) --while moving to center, rotate matching objects back to upright position if oldVector ~= newVector then transition.to( item1, {time=500, rotation = 0} ) end addPointToPlayer(1) end end
As always, thanks for your help!