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-- 将屏幕GUI值替换为您拥有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
要示示此过程,请参阅 LocalScript 中的 ScreenGui ,其中 LoadingScreen 是一个名为 2> LoadingScreen2> 的自定义加载屏幕:
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
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()