Created
May 21, 2020 20:24
-
-
Save TheEpicFace007/7bd270f0519fa6535b531f7228fe9b39 to your computer and use it in GitHub Desktop.
Image zoomer module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local TweenService = game:GetService("TweenService") | |
local image_zoomer = {} | |
image_zoomer.__index = image_zoomer | |
-- @image image where you will zoom. must be a to_zoom | |
-- @what_type_used what type of unit u use for ur image | |
function image_zoomer.set_zoom(to_zoom) | |
assert(to_zoom.ClassName ~= "ImageLabel" or "ImageButton","Error in #1, you have to provide a image label or a image button") | |
local image = {} | |
setmetatable(image,image_zoomer) | |
image.to_zoom = to_zoom | |
image.og_pos = image.to_zoom.Size | |
image.old_pos = image.to_zoom.Size | |
image.easing_style = Enum.EasingStyle.Quad | |
image.tween_duration = 0.2 | |
-- zoom in | |
image.to_zoom.MouseWheelForward:Connect(function() | |
local new_size | |
new_size = image.old_pos + UDim2.fromOffset(10,10) | |
to_zoom:TweenSize( | |
new_size, | |
Enum.EasingDirection.Out, | |
image.easing_style, | |
image.tween_duration, | |
true, | |
nil | |
) | |
image.old_pos = new_size | |
end) | |
image.to_zoom.TouchPan:Connect(function() | |
local new_size | |
new_size = image.old_pos + UDim2.fromOffset(10,10) | |
to_zoom:TweenSize( | |
new_size, | |
Enum.EasingDirection.Out, | |
image.easing_style, | |
image.tween_duration, | |
true, | |
nil | |
) | |
image.old_pos = new_size | |
end) | |
-- zoom out | |
image.to_zoom.MouseWheelBackward:Connect(function() | |
local new_size | |
new_size = image.old_pos - UDim2.fromOffset(10,10) | |
to_zoom:TweenSize( | |
new_size, | |
Enum.EasingDirection.Out, | |
image.easing_style, | |
image.tween_duration, | |
true, | |
nil | |
) | |
image.old_pos = new_size | |
end) | |
image.to_zoom.TouchPinch:Connect(function() | |
local new_size | |
new_size = image.old_pos - UDim2.fromOffset(10,10) | |
to_zoom:TweenSize( | |
new_size, | |
Enum.EasingDirection.Out, | |
image.easing_style, | |
image.tween_duration, | |
true, | |
nil | |
) | |
image.old_pos = new_size | |
end) | |
-- return back to it's og pos | |
image.to_zoom.InputEnded:Connect(function() | |
to_zoom:TweenSize( | |
image.og_pos, | |
Enum.EasingDirection.Out, | |
image.easing_style, | |
image.tween_duration, | |
true, | |
nil | |
) | |
image.old_pos = image.og_pos | |
end) | |
return image | |
end | |
function image_zoomer:set_duratiom(duration) | |
self.tween_duration = duration | |
end | |
function image_zoomer:set_easing_style(easing_style) | |
self.easing_style = easing_style | |
end | |
return image_zoomer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment