กำลังโหลดหน้าจอ

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

Roblox แสดงหน้าจอโหลดเริ่มต้นเมื่อผู้ใช้เชื่อมต่อกับประสบการณ์ แต่คุณสามารถปรับแต่งประสบการณ์ของคุณด้วยหน้าจอโหลดที่กำหนดเองที่มีเนื้อหาคงที่หรือเคลื่อนไหว

แสดงหน้าจอโหลดที่กําหนดเอง

เพื่อแสดงหน้าจอโหลดที่กําหนดเองคุณสามารถออกแบบ ScreenGui ตัวอย่างโดยตรงภายใน LocalScript หรือคุณสามารถอ้างอิงวัตถุ ScreenGui ในพื้นที่ทํางานของคุณทั้งสองตัวเลือกใช้ ReplicatedFirst เนื่องจากบริการนี้ที่จะสร้างตัวอย่างให้กับลูกค้าก่อนที่จะสร้างสิ่งอื่นซึ่งช่วยให้แน่ใจว่าหน้าจอโหลดของคุณเป็นสิ่งแรกที่ผู้ใช้เห็นเมื่อพวกเขาเข้าสู่ประสบการณ์ของคุณ

ออกแบบภายใน LocalScripts

เพื่อออกแบบและแสดงหน้าจอโหลดที่กําหนดเอง:

  1. ใน ReplicatedFirst สร้าง LocalScript
  2. ใช้ตัวอย่างโค้ดต่อไปนี้เพื่อสร้างและปรับแต่งวัตถุ ScreenGuiคุณสามารถแก้ไขโค้ดต่อไปนี้ด้วยค่าของคุณเองเพื่อสร้างการออกแบบของคุณ:

local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.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.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
-- ลบหน้าจอโหลดเริ่มต้น
ReplicatedFirst:RemoveDefaultLoadingScreen()
task.wait(5) -- บังคับให้หน้าจอปรากฏเป็นเวลาอย่างน้อยหนึ่งวินาที
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui:Destroy()

หน้าจอ ScreenGuis อ้างอิง

แทนที่จะสร้าง ScreenGui ผ่าน LocalScript คุณสามารถอ้างอิง ScreenGui ที่มีอยู่ในพื้นที่ทำงานของคุณโดยตรงได้ตรวจสอบให้แน่ใจว่าประสบการณ์ของคุณรวมถึง ภายใน และมีองค์ประกอบ UI เช่น และ จากนั้นตั้งค่าให้เป็นหน้าจอโหลดโดยอ้างอิงถึงมันภายใน วิธีนี้ช่วยให้คุณดูหน้าจอโหลดของคุณได้อย่างง่ายดายในขณะที่คุณกําลังสร้างมัน

เพื่อสาธิตกระบวนการนี้ ต่อไปนี้ LocalScript อ้างอิงถึง ScreenGui ชื่อ หน้าจอโหลด ภายใน ReplicatedFirst จากนั้นจะลบหน้าจอโหลดเริ่มต้นดังนั้นหน้าจอโหลดเดียวที่ผู้ใช้สามารถเห็นได้คือหน้าจอโหลดเองที่กำหนดเอง:


local Players = game:GetService("Players")
local ReplicatedFirst = game:GetService("ReplicatedFirst")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = ReplicatedFirst.LoadingScreen
screenGui.IgnoreGuiInset = true
screenGui.Parent = playerGui
-- ลบหน้าจอโหลดเริ่มต้น
ReplicatedFirst:RemoveDefaultLoadingScreen()
task.wait(5) -- บังคับให้หน้าจอปรากฏเป็นเวลาอย่างน้อยหนึ่งวินาที
if not game:IsLoaded() then
game.Loaded:Wait()
end
screenGui: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.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = Instance.new("ScreenGui")
screenGui.IgnoreGuiInset = true
screenGui.Parent = playerGui
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(1, 0, 1, 0)
textLabel.BackgroundColor3 = Color3.fromRGB(0, 20, 40)
textLabel.Font = Enum.Font.GothamMedium
textLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)
textLabel.Text = "Loading"
textLabel.TextSize = 28
textLabel.Parent = screenGui
local loadingRing = Instance.new("ImageLabel")
loadingRing.Size = UDim2.new(0, 256, 0, 256)
loadingRing.BackgroundTransparency = 1
loadingRing.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() then
game.Loaded:Wait()
end
screenGui:Destroy()