您好 roblox 作業室的腳本撰寫者,
我是一名中級腳本構建者,需要一些有關游戲圖形用戶界面的幫助。
我有一個帶有播放按鈕的開始螢屏,如下所示:

我試圖在單擊按鈕時淡出 gui,但沒有一個教程有效。這是我的按鈕腳本:
local button = script.Parent
local gui = script.Parent.Parent.Parent
button.MouseButton1Down:Connect(function()
gui.Enabled = false
end)
我不知道如何進行更改,會是 BackgroundTransparency 嗎?您將如何以 0.01 的增量將透明度從 0 更改為 1?
我試圖用 for 回圈使 gui 淡出,更改 BackgroundTransparency 但這沒有用,這是代碼:
local button = script.Parent
local gui = script.Parent.Parent.Parent
button.MouseButton1Down:Connect(function()
for i = 0, 100, 1 do
gui.Frame.BackgroundTransparency 0.01
wait(0.01)
gui.Enabled = false
end
end)
我不知道為什么它不起作用。如果我有錯別字之類的,請告訴我。謝謝!
uj5u.com熱心網友回復:
回圈解決方案有一些錯別字,這里是固定的:
local button = script.Parent
local gui = script.Parent.Parent.Parent
button.MouseButton1Down:Connect(function()
for i = 0, 100 do
gui.Frame.BackgroundTransparency = 0.01 -- = adds 0.01 each time
task.wait(0.01) -- better than wait(0.01)
end
gui.Enabled = false
end)
然而,這不是一個理想的解決方案。更好的系統會使用 Roblox 的 TweenService 來更改 gui 的透明度。Tweens 不那么緊張,更容易修改,并且有很多自定義屬性,包括重復、改變時間長度和緩動樣式(例如,開始時速度較快,然后在接近尾聲時變慢;請參閱Roblox 檔案上的緩動樣式)。
local TweenService = game:GetService("TweenService")
local button = script.Parent
local gui = script.Parent.Parent.Parent
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- Easing Style
Enum.EasingDirection.Out -- Easing Direction
-- See https://create.roblox.com/docs/reference/engine/datatypes/TweenInfo for more available properties
)
local tween = TweenService:Create(
gui.Frame, -- Instance to tween
tweenInfo, -- TweenInfo
{ Transparency = 1 } -- What we want to change
)
button.MouseButton1Down:Connect(function()
tween:Play()
tween.Completed:Wait() -- Wait until tween is complete
gui.Enabled = false
end)
盡管這兩種解決方案都只改變了背景的透明度,因此播放按鈕等子元素將保持可見,直到 gui 被禁用。您可能希望將 Frame 替換為 CanvasGroup,這也會在其 GroupTransparency 屬性更改時更改其子項的透明度。
local tween = TweenService:Create(
gui.CanvasGroup, -- Instance to tween
tweenInfo, -- TweenInfo
{ GroupTransparency = 1 } -- What we want to change
)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/534241.html
標籤:用户界面背景罗布乐思褪色
