Roblox 會在用戶連接到體驗時顯示預設載入屏幕,但您可以使用包含靜態或動畫內容的自訂載入屏幕來個人化您的體驗。
顯示自訂載入屏幕
要顯示自訂載入頁面,您可以在 ScreenGui 內直接設計一個 LocalScript 實例,或者您可以在您的工作區內參考一個 ScreenGui 對象。 兩個選項都使用 2>Class.ReplicatedFirst2> ,因為這
在本地指令碼中設計
要設計並顯示自訂載入屏幕:
- 在 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-- 用自擁有的值替換屏幕GUIlocal 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 的 Class.ScreenGui ,內含 2>Class.Screen2> 作為載入屏幕,然後移除預設載入屏幕,因此用戶可以看到的載入屏幕只是您自己的載入屏幕:
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()
添加動畫
除了靜態自訂載入屏幕外,您還可以添加動畫來改善載入屏幕並指示載入進度。最��
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()