Ozzypig

TouchSwipe Example

May 20th, 2018
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.29 KB | None | 0 0
  1. local frame = script.Parent
  2. frame.Active = true
  3.  
  4. -- How far the frame should bounce on a successful swipe
  5. local BOUNCE_DISTANCE = 50
  6.  
  7. -- Current state of the frame
  8. local basePosition = frame.Position
  9. local hue = 0
  10. local saturation = 128
  11.  
  12. local function updateColor()
  13.     frame.BackgroundColor3 = Color3.fromHSV(hue/256, saturation/256, 1)
  14. end
  15.  
  16. local function onTouchSwipe(swipeDir, touchCount)
  17.     -- Change the BackgroundColor3 based on the swipe direction
  18.     local deltaPos
  19.     if swipeDir == Enum.SwipeDirection.Right then
  20.         deltaPos = UDim2.new(0, BOUNCE_DISTANCE, 0, 0)
  21.         hue = (hue + 16) % 255
  22.     elseif swipeDir == Enum.SwipeDirection.Left then
  23.         deltaPos = UDim2.new(0, -BOUNCE_DISTANCE, 0, 0)
  24.         hue = (hue - 16) % 255
  25.     elseif swipeDir == Enum.SwipeDirection.Up then
  26.         deltaPos = UDim2.new(0, 0, 0, -BOUNCE_DISTANCE)
  27.         saturation = (saturation + 16) % 255
  28.     elseif swipeDir == Enum.SwipeDirection.Down then
  29.         deltaPos = UDim2.new(0, 0, 0, BOUNCE_DISTANCE)
  30.         saturation = (saturation - 16) % 255
  31.     else
  32.         deltaPos = UDim2.new()
  33.     end
  34.     -- Update the color and bounce the frame a little
  35.     updateColor()
  36.     frame.Position = basePosition + deltaPos
  37.     frame:TweenPosition(basePosition, Enum.EasingDirection.Out, Enum.EasingStyle.Bounce, .7, true)
  38. end
  39.  
  40. frame.TouchSwipe:connect(onTouchSwipe)
  41. updateColor()
Advertisement
Add Comment
Please, Sign In to add comment