Classe motore
RunService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
BindToRenderStep(name: string,priority: number,function: function):() |
BindToSimulation(function: function,frequency: Enum.StepFrequency,priority: number):RBXScriptConnection |
GetPredictionStatus(context: Instance):Enum.PredictionStatus |
Pause():() |
Reset():() |
Run():() |
SetPredictionMode(context: Instance,mode: Enum.PredictionMode):() |
Stop():() |
UnbindFromRenderStep(name: string):() |
Eventi
Heartbeat(deltaTime: number):RBXScriptSignal |
Misprediction(time: number,instances: {any},stats: Dictionary):RBXScriptSignal |
PostSimulation(deltaTimeSim: number):RBXScriptSignal |
PreAnimation(deltaTimeSim: number):RBXScriptSignal |
PreRender(deltaTimeRender: number):RBXScriptSignal |
PreSimulation(deltaTimeSim: number):RBXScriptSignal |
RenderStepped(deltaTime: number):RBXScriptSignal |
Rollback(time: number):RBXScriptSignal |
Stepped(time: number,deltaTime: number):RBXScriptSignal |
Riferimento API
Proprietà
Metodi
BindToRenderStep
Restituzioni
()
Campioni di codice
Cornice che si muove in cerchio
local RunService = game:GetService("RunService")
-- Quanto veloce dovrebbe muoversi il frame
local SPEED = 2
local frame = script.Parent
frame.AnchorPoint = Vector2.new(0.5, 0.5)
-- Un'equazione parametrica semplice di un cerchio
-- centrato in (0.5, 0.5) con raggio (0.5)
local function circle(t)
return 0.5 + math.cos(t) * 0.5, 0.5 + math.sin(t) * 0.5
end
-- Tieni traccia del tempo attuale
local currentTime = 0
local function onRenderStep(deltaTime)
-- Aggiorna il tempo attuale
currentTime = currentTime + deltaTime * SPEED
-- ...e la posizione del frame
local x, y = circle(currentTime)
frame.Position = UDim2.new(x, 0, y, 0)
end
-- Questo è solo un effetto visivo, quindi usa la priorità "Last"
RunService:BindToRenderStep("FrameCircle", Enum.RenderPriority.Last.Value, onRenderStep)
--RunService.RenderStepped:Connect(onRenderStep) -- Funziona anche, ma non raccomandatoFunzione personalizzata di RunService
local RunService = game:GetService("RunService")
local function checkDelta(deltaTime)
print("Tempo dall'ultimo passo di rendering:", deltaTime)
end
RunService:BindToRenderStep("Controlla delta", Enum.RenderPriority.First.Value, checkDelta)Collegare e Disconnettere una Funzione
local RunService = game:GetService("RunService")
-- Passo 1: Dichiarare la funzione e un nome
local NAME = "Stampa Ciao"
local function printHello()
print("Ciao")
end
-- Passo 2: Collegare la funzione
RunService:BindToRenderStep(NAME, Enum.RenderPriority.First.Value, printHello)
-- Passo 3: Disconnettere la funzione
RunService:UnbindFromRenderStep(NAME)BindToSimulation
RunService:BindToSimulation(
Parametri
| Valore predefinito: "Hz30" |
| Valore predefinito: 2000 |
Restituzioni
Campioni di codice
Sincronizzazione della proprietà colore di un oggetto
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local somePart:BasePart = Workspace:WaitForChild("Part")
RunService:BindToSimulation(function(deltaTime: number)
local syncdColor = Color3.fromHSV(math.fmod(time(), 1.0), 1.0, 1.0)
somePart:SetAttribute("SyncdColor", syncdColor)
end)
RunService.RenderStepped:Connect(function(deltaTime: number)
local syncdColor = somePart:GetAttribute("SyncdColor")
somePart.Color = syncdColor
end)GetPredictionStatus
Parametri
Restituzioni
Pause
RunService:Pause():()
Restituzioni
()
Reset
Run
RunService:Run():()
Restituzioni
()
SetPredictionMode
Parametri
Restituzioni
()
Stop
RunService:Stop():()
Restituzioni
()
Eventi
Misprediction
Parametri
PostSimulation
PreAnimation
PreRender
PreSimulation
Stepped