當使用者連接到體驗時,Roblox 會顯示預設載入屏幕,但您可以使用包含靜態或動畫內容的自訂載入屏幕來個人化您的體驗。
顯示自訂載入屏幕
若要顯示自訂載入屏幕,您可以直接在 中設計一個實例,或可以在工作區中參考 對象。兩個選項都使用 ReplicatedFirst , 因為這是一種服務,在其他任何東西複製之前複製到客戶端的實例。這樣可以確保您的載入頁面是用戶進入體驗時第一看到的內容。
在本地腳本中設計
要設計並顯示自訂載入屏幕:
- 在 ReplicatedFirst 中,創建一個 LocalScript。
- 使用以下代碼示例來創建和自定義 ScreenGui 物件。您可以使用自己的值修改以下代碼來創建設計:
local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local screenGui = Instance.new("ScreenGui")screenGui.IgnoreGuiInset = truescreenGui.Parent = playerGui-- 以自擁有的值取代 ScreenGui 值local textLabel = Instance.new("TextLabel")textLabel.Size = UDim2.new(1, 0, 1, 0)textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)textLabel.Font = Enum.Font.GothamMediumtextLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)textLabel.Text = "Loading"textLabel.TextSize = 28textLabel.Parent = screenGui-- 移除預設載入屏幕ReplicatedFirst:RemoveDefaultLoadingScreen()task.wait(5) -- 強制屏幕在最少數秒內出現if not game:IsLoaded() thengame.Loaded:Wait()endscreenGui:Destroy()
參考屏幕指南
您也可以直接在工作區中參考現有的 ScreenGui ,而不是通過 LocalScript 創建 ScreenGui 。確保您的體驗包含 ScreenGui 內的 ReplicatedFirst 以及 ScreenGui 包含像 TextLabels 和 ImageLabels 等用戶介面元素,然後將其設為載入屏幕,通過在 LocalScript 中引用它來引用它。這個方法讓你可以在創建載入屏幕時輕鬆查看載入屏幕。
為了展示此過程,以下 LocalScript 參考內含 ScreenGui 名為 載入屏幕 的 ReplicatedFirst ,然後移除預設載入頁面,因此使用者只能看到自己的自定載入頁面:
local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local screenGui = ReplicatedFirst.LoadingScreenscreenGui.IgnoreGuiInset = truescreenGui.Parent = playerGui-- 移除預設載入屏幕ReplicatedFirst:RemoveDefaultLoadingScreen()task.wait(5) -- 強制屏幕在最少數秒內出現if not game:IsLoaded() thengame.Loaded:Wait()endscreenGui:Destroy()
新增動畫
除了靜態自訂載入屏幕外,您還可以添加動畫來增強載入屏幕並指示載入進度。最簡單的方法是創建 UI 元素,例如 TextLabel 或 ImageLabel,然後使用 TweenService 來動畫它。例如,以下代碼示例創建了一個新的 ScreenGui 並帶有子 ImageLabel ,移除了預載屏幕,然後 TweenService 持續旋轉 ImageLabel 直到體驗載入:
local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local TweenService = game:GetService("TweenService")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local screenGui = Instance.new("ScreenGui")screenGui.IgnoreGuiInset = truescreenGui.Parent = playerGuilocal textLabel = Instance.new("TextLabel")textLabel.Size = UDim2.new(1, 0, 1, 0)textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)textLabel.Font = Enum.Font.GothamMediumtextLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)textLabel.Text = "Loading"textLabel.TextSize = 28textLabel.Parent = screenGuilocal loadingRing = Instance.new("ImageLabel")loadingRing.Size = UDim2.new(0, 256, 0, 256)loadingRing.BackgroundTransparency = 1loadingRing.Image = "rbxassetid://4965945816"loadingRing.AnchorPoint = Vector2.new(0.5, 0.5)loadingRing.Position = UDim2.new(0.5, 0, 0.5, 0)loadingRing.Parent = screenGui-- 移除預設載入屏幕ReplicatedFirst:RemoveDefaultLoadingScreen()local tweenInfo = TweenInfo.new(4, Enum.EasingStyle.Linear, Enum.EasingDirection.In, -1)local tween = TweenService:Create(loadingRing, tweenInfo, {Rotation = 360})tween:Play()task.wait(5) -- 強制屏幕在最少數秒內出現if not game:IsLoaded() thengame.Loaded:Wait()endscreenGui:Destroy()