Roblox は、ユーザーがエクスペリエンスに接続すると、デフォルトのロード画面を表示しますが、静的またはアニメーションコンテンツを含むカスタムロード画面でエクスペリエンスをカスタマイズできます。
カスタムロード画面を表示する
カスタムロードスクリーンを表示するには、ScreenGui インスタンスを直接 LocalScript 内に設計するか、ワークスペース内の ScreenGui オブジェクトを参照できます。両方のオプションは、他の何よりも先にインスタンスをクライアントにレプリケートするこのサービスを使用していますReplicatedFirst。これにより、ロード画面がユーザーがエクスペリエンスに入るときに最初に見るものになります。
ローカルスクリプト内での設計
カスタムロードスクリーンを設計して表示するには:
- In 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 のような UI 要素を含め、 LocalScript に参照してロード画面として設定します。このメソッドでは、作成中のロード画面を簡単に表示できます。
このプロセスを示すために、次の は、 という名前の ロード画面 を 内に参照し、ユーザーが見ることができる唯一のロード画面は、自分のカスタムロード画面です:
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()
アニメーションを追加
静的なカスタムロード画面に加えて、ロード画面を強化し、ロード進行状況を示すためにアニメーションを追加できます。これを行う最も簡単な方法は、TextLabel または ImageLabel などの UI 要素を作成し、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 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()