Hi, I am working on changing my ui designs and I want to learn how to make this effect where the pattern moves but stays the same size.
I’ve already posted about this a long time ago but after trying the code, it didn’t work for me.
I couldn’t find anything about this pattern.
Here’s my code:
local PatternMovement = {}
function PatternMovement.MovePattern(Pattern,SecondsPerCycle)
local RunService = game:GetService("RunService")
local Image = Pattern
local Distance = 0
local secondsPerCycle = SecondsPerCycle
local speed = 1 / secondsPerCycle
Connection = nil
Connection = RunService.RenderStepped:Connect(function(dt)
Distance += dt * speed
-- This is called the modulo operator and wraps the distance from 0 to 1.
Distance = Distance % 1
-- Subtracts 200 here so that the GUI's left edge stays off the side of the screen. You'll need to make the object larger than 1,0,1,0 to make sure it covers everything.
Image.Position = UDim2.fromOffset(Distance * 100 - 200, 0)
end)
end
function PatternMovement.DisconnectPatterns()
if Connection ~= nil then
Connection:Disconnect()
end
end
return PatternMovement
This script was taken from the old post by the way, just made it a module.
local PatternMovement = {}
function PatternMovement.MovePattern(Pattern,SecondsPerCycle)
local RunService = game:GetService("RunService")
local Image = Pattern
local Distance = 0
local secondsPerCycle = SecondsPerCycle
local speed = 1 / secondsPerCycle
Connection = nil
Connection = RunService.RenderStepped:Connect(function(dt)
Distance += dt * speed
-- This is called the modulo operator and wraps the distance from 0 to 1.
Distance = Distance % 1
-- Subtracts 200 here so that the GUI's left edge stays off the side of the screen. You'll need to make the object larger than 1,0,1,0 to make sure it covers everything.
Image.Position = UDim2.fromOffset(Distance * 200 - 200, 0)
end)
end
function PatternMovement.DisconnectPatterns()
if Connection ~= nil then
Connection:Disconnect()
end
end
return PatternMovement