Advertisement
lvs

Untitled

lvs
Jan 7th, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. local function touchPlay(event)
  2.     local bounds = buttonPlay.contentBounds
  3.     local isWithinBounds = bounds.xMin <= event.x and bounds.xMax >= event.x and bounds.yMin <= event.y and bounds.yMax >= event.y
  4.     if event.phase == "began" then
  5.         buttonPlay.currentFrame = 2
  6.         display.getCurrentStage():setFocus(buttonPlay, event.id)
  7.         buttonPlay.isFocused = true
  8.     elseif buttonPlay.isFocused then
  9.         if event.phase == "moved" then
  10.             if isWithinBounds then
  11.                 buttonPlay.currentFrame = 2
  12.             else
  13.                 buttonPlay.currentFrame = 1
  14.             end
  15.         elseif event.phase == "ended" or event.phase == 'cancelled' then
  16.             if event.phase == "ended" and isWithinBounds then
  17.                 -- change scene here
  18.             end
  19.             buttonPlay.currentFrame = 1
  20.             display.getCurrentStage():setFocus(buttonPlay, nil)
  21.             buttonPlay.isFocused = false
  22.         end
  23.     end
  24. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement