I am writing a program in Lua.
I drew a circle and want the circle to move up or down depending on which button is clicked. I am very new and have been reading Burton’s book. I have tried different ways to do this but am getting weird results. I commented out some of the attempts. Clicking on the button makes it move a little then go back into original position. The move button down function is commented out and yet clicked on the down button makes it move. Can someone please point me in the correct direction?
local w = display.contentWidth local h = display.contentHeight local btnUp = display.newImage("btnUp.png") local btnDown = display.newImage("btnDown.png") --local wB = btnUp.width -- the buttons are the same size so only one set of sizes needs to be saved off --local hB = btnUp.height --[[Center the buttons based on display width and height --]] btnUp.x = w / 2 - 100 -- sets the left & right to half the display width btnUp.y = h -75 -- sets the up & down to 50px from bottom btnDown.x = w / 2 + 100 -- sets the left & right to half the display width btnDown.y = h -75 -- sets the up & down to 50px from bottom local circle1 = display.newCircle(150, 150, 50) circle1.strokeWidth=10 circle1:setFillColor(0,0,0) circle1:setStrokeColor(255,0,0) circle1.yReference = 110 function moveCirclesUp(event) --circle1.x = circle1.x - 50 --circle1.y = circle1.y - 50 transition.to(circle1, { y = circle1.y - 50}) end function moveCirclesDown(event) --circle1.x = circle1.x + 50 circle1.y = circle1.y + 50 --transition.to(circle1, {x = circle1.x , y = circle1.y + 50}) -- circle1:translate(0, 50) end btnUp:addEventListener("tap" , moveCirclesUp) btnDown:addEventListener("tap" , moveCirclesDown)