Skip to content

Instantly share code, notes, and snippets.

@xen
Created September 21, 2012 09:46
Show Gist options
  • Select an option

  • Save xen/3760658 to your computer and use it in GitHub Desktop.

Select an option

Save xen/3760658 to your computer and use it in GitHub Desktop.
First code
local w,h = display.contentWidth, display.contentHeight
local rec_width = 200
local rec_height = 100
local btnText = "Press me"
local rect1 = display.newRect((w-rec_width)/2, (h-rec_height)/2, rec_width, rec_height )
local text = display.newText(btnText, w/2, h/2, native.systemFont, 30)
text:setTextColor(100, 100, 100)
function setRectBack( event )
text.text = "Run away"
transition.to( rect1, { time=500, x=(w)/2, y=(h)/2} )
transition.to( text, { time=500, x=(w)/2, y=(h)/2, onComplete = endMove} )
end
function endMove( )
text.text = btnText
end
function eventphase( event )
if event.phase == "began" then
text.text = "began"
end
if event.phase == "moved" then
text.text = "moved"
end
if event.phase == "ended" then
text.text = "ended"
tmr = timer.performWithDelay(1000, setRectBack, 1)
end
rect1.x = event.x
rect1.y = event.y
text.x = event.x
text.y = event.y
end
rect1:addEventListener("touch", eventphase)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment