FBase
Inherits BaseObject
FBase provides a structure for setting up and fetching Instances in an OOP fashion while still being fluid in its interactions with Fusion. It is intended to be used as a base class for other FusionOnRails classes.
Any class that inherits this can have their .new() constructor called via calling the class itself as a function in order to match Fusion.
[NOTE] :Bind must be called exactly once. If you do not pass anything to the FBase constructor then you must call this method yourself, ideally in the constructor of the inheriting class.
[EXAMPLE USAGE]
-- (Assume Fusion Imports)
local ExampleUI = setmetatable({}, FBase)
ExampleUI.__index = ExampleUI
ExampleUI.ClassName = "ExampleUI"
function ExampleUI.new(props)
local self = setmetatable(FBase.new(), ExampleUI)
self.Pulsate = Value(false)
self:Bind(New "Frame" {
Name = props.Name;
Transparency = Computed(function(use) -- Makes the frame fade in and out repeatedly
if use(self.Pulsate) then
local t = use(self:Clock())
return math.sin(t) / 2 + 0.5
end
return 0
end);
})
return self
end
-------------------------------------
local ExampleUI = Import("ExampleUI")
local myUI = ExampleUI {
Name = "MyUI";
}
print(myUI:GetInstance().Name) -- "MyUI"
self.Pulsate:set(true) -- turns on the pulsating effect
task.wait(5)
myUI:Destroy() -- Destroys the FBase and its GuiObject
Functions
getObjectFromInstance
staticFetches the FBase that is bound to the given GuiObject.
is
staticFBase.
is
(
obj:
any
--
The object to check
) →
boolean
--
Whether or not the object inherits FBase
Can but used to check if a passed object inherits FBase.
new
staticCreates a new FBase.
Destroy
FBase:
Destroy
(
) →
(
)
Destroys the FBase and its Instance if not done so already. This method is automatically called if the bound Gui is Destroyed.
Bind
FBase:
Bind
(
props:
table?
,
--
The default props to apply. (Only used if a ClassName is passed)
priorityProps:
table?
--
A table of props that will override the indices of the props table. (Only used if a ClassName is passed)
) →
GuiObject
Initializes the FBase with a Instance. It binds this Object's lifecycle to the lifecycle of the Instance. If either is destroyed, the other is aswell. This method should be called exactly once and will throw an error if called again.
IsBound
FBase:
IsBound
(
) →
boolean
Checks to see if the FBase is bound to an Instance.
GetInstance
Returns the Instance that this FBase is bound to.
Clock
FBase:
Clock
(
) →
StateObject
<
number
>
Fetches a state object JIT that can be used to force update computeds each frame. This state will update every frame at RenderStep for the duration of the FBase's lifetime. The number stored in the state is the time since the FBase was constructed.
HeartbeatUpdate
FBase:
HeartbeatUpdate
(
dt:
number
) →
(
)
If this method is present on an FBase Class, then it will be
automatically connected to RunService.Heartbeat
.
function MyFBaseClass:HeartbeatUpdate(dt)
end
SteppedUpdate
FBase:
SteppedUpdate
(
dt:
number
) →
(
)
If this method is present on an FBase Class, then it will be
automatically connected to RunService.Stepped
.
function MyFBaseClass:SteppedUpdate(dt)
end
RenderSteppedUpdate
This item only works when running on the client. ClientFBase:
RenderSteppedUpdate
(
dt:
number
) →
(
)
If this method is present on an FBase Class, then it will be
automatically connected to RunService.RenderStepped
. If
the [FBase].RenderPriority
field is found, then the
component will instead use RunService:BindToRenderStep()
to bind the function.
-- Example that uses `RunService.RenderStepped` automatically:
function MyFBaseClass:RenderSteppedUpdate(dt)
end
-- Defining a RenderPriority will force the component to use BindToRenderStep instead
MyFBaseClass.RenderPriority = Enum.RenderPriority.Camera.Value
function MyFBaseClass:RenderSteppedUpdate(dt)
end