Roblox จะแสดงหน้าจอโหลดเริ่มต้นเมื่อผู้ใช้เชื่อมต่อกับเกม แต่คุณสามารถปรับแต่งเกมของคุณด้วยหน้าจอโหลดแบบกำหนดเองที่มีเนื้อหาคงที่หรือเคลื่อนไหว
การนำไปใช้
เพื่อแสดงหน้าจอโหลดแบบกำหนดเอง คุณสามารถออกแบบอินสแตนซ์ ScreenGui โดยตรงภายใน LocalScript หรือคุณสามารถอ้างอิงถึงออบเจ็กต์ ScreenGui ในลำดับชั้นสถานที่ของคุณ ตัวเลือกทั้งสองนี้ใช้งาน ReplicatedFirst เนื่องจากบริการนี้จะทำการทำซ้ำอินสแตนซ์ไปยังลูกค้าก่อนที่จะมีการทำซ้ำสิ่งอื่น ๆ การทำเช่นนี้จะทำให้หน้าจอโหลดของคุณเป็นสิ่งแรกที่ผู้ใช้เห็นเมื่อพวกเขาเข้าสู่เกมของคุณ
จากสคริปต์
เพื่อออกแบบและแสดงหน้าจอโหลดแบบกำหนดเองทั้งหมดจาก LocalScript:
- ใน ReplicatedFirst สร้าง LocalScript
- วางตัวอย่างโค้ดด้านล่างเพื่อสร้างและปรับแต่งออบเจ็กต์ ScreenGui คุณสามารถปรับค่าตัวอย่างโค้ดด้านล่างด้วยค่าของคุณเองเพื่อสร้างการออกแบบของคุณ
หน้าจอโหลดที่สร้างจากสคริปต์local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local loadingScreen = Instance.new("ScreenGui")loadingScreen.IgnoreGuiInset = trueloadingScreen.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.DenkOnetextLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)textLabel.Text = "กำลังโหลด"textLabel.TextSize = 32textLabel.Parent = loadingScreen-- ลบหน้าจอโหลดเริ่มต้นReplicatedFirst:RemoveDefaultLoadingScreen()task.wait(5) -- บังคับให้หน้าจอโหลดแบบกำหนดแสดงอย่างน้อย 5 วินาทีif not game:IsLoaded() thengame.Loaded:Wait()endloadingScreen:Destroy()
จาก GUI ที่มีอยู่
แทนที่จะสร้างหน้าจอโหลด ScreenGui ทั้งหมดผ่าน LocalScript คุณยังสามารถอ้างอิงถึง ScreenGui ที่มีอยู่ในลำดับชั้นสถานที่ของคุณ ตรวจสอบให้แน่ใจว่าเกมของคุณรวม ScreenGui ที่อ้างถึงภายใน ReplicatedFirst และ ScreenGui รวมถึงองค์ประกอบ UI เช่น TextLabels และ ImageLabels
เพื่อสาธิตกระบวนการนี้ LocalScript ต่อไปนี้จะอ้างถึง ScreenGui ที่ชื่อ LoadingScreen ภายใน ReplicatedFirst จากนั้นจะลบหน้าจอโหลดเริ่มต้นเพื่อให้หน้าจอโหลดที่ผู้เล่นสามารถเห็นได้คือหน้าจอโหลดแบบกำหนดเองของคุณเอง
อ้างอิงถึงหน้าจอโหลดที่มีอยู่local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local loadingScreen = ReplicatedFirst:FindFirstChild("LoadingScreen")if loadingScreen thenloadingScreen.IgnoreGuiInset = trueloadingScreen.Parent = playerGui-- ลบหน้าจอโหลดเริ่มต้นReplicatedFirst:RemoveDefaultLoadingScreen()task.wait(5) -- บังคับให้หน้าจอแสดงอย่างน้อย 5 วินาทีif not game:IsLoaded() thengame.Loaded:Wait()endloadingScreen:Destroy()end
เพิ่มการเคลื่อนไหว
นอกเหนือจากหน้าจอโหลดแบบกำหนดเองที่มีเนื้อหาคงที่แล้ว คุณสามารถเพิ่มการเคลื่อนไหวเพื่อปรับปรุงหน้าจอโหลดและบ่งบอกถึงความก้าวหน้าของการโหลด วิธีที่ง่ายที่สุดในการทำเช่นนี้คือการสร้างองค์ประกอบ UI เช่น TextLabel หรือ ImageLabel แล้วทำการสร้างการเคลื่อนไหวโดยใช้ TweenService ตัวอย่างเช่น ตัวอย่างโค้ดต่อไปนี้สร้าง ScreenGui ใหม่ที่มีบุตร ImageLabel ลบหน้าจอโหลดเริ่มต้น และจากนั้น TweenService จะค่อยๆ ปรับให้เห็นและหมุนองค์ประกอบกลางจนกว่าเกมจะโหลดเสร็จ
หน้าจอโหลดที่สร้างจากสคริปต์ (เคลื่อนไหว)local Players = game:GetService("Players")local ReplicatedFirst = game:GetService("ReplicatedFirst")local TweenService = game:GetService("TweenService")local player = Players.LocalPlayerlocal playerGui = player:WaitForChild("PlayerGui")local loadingScreen = Instance.new("ScreenGui")loadingScreen.IgnoreGuiInset = trueloadingScreen.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.DenkOnetextLabel.TextColor3 = Color3.new(0.8, 0.8, 0.8)textLabel.Text = "กำลังโหลด"textLabel.TextSize = 32textLabel.TextTransparency = 1textLabel.Parent = loadingScreenlocal 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.ImageTransparency = 1loadingRing.Parent = loadingScreen-- ลบหน้าจอโหลดเริ่มต้นReplicatedFirst:RemoveDefaultLoadingScreen()-- เริ่มต้นและเริ่มการสร้างการเคลื่อนไหวให้ค่อยๆ ปรับให้เห็นlocal fadeTweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out, 0, false, 2)local fadeTween1 = TweenService:Create(textLabel, fadeTweenInfo, {TextTransparency = 0})local fadeTween2 = TweenService:Create(loadingRing, fadeTweenInfo, {ImageTransparency = 0})fadeTween1:Play()fadeTween2:Play()-- เริ่มต้นและเริ่มการสร้างการเคลื่อนไหวการหมุน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) -- บังคับให้หน้าจอแสดงอย่างน้อย 5 วินาทีif not game:IsLoaded() thengame.Loaded:Wait()endloadingScreen:Destroy()