Now that we know that all actors are in a Screen, it's time to add some of our own.
Head over to the folder of the theme you just created, and make a BGAnimations folder. This folder will contain all of the information for the actors that will be present on each screen.
In this example, we'll make our own actors on ScreenTitleMenu, which as the name implies, is the Title screen, where you get to see the options like "Start Game", "Options", "Edit Songs/Courses", etc.
Create a file inside your BGAnimations folder called ScreenTitleMenu overlay.lua
. Since we're working in Lua, the same rules on that programming language apply here.
To start, let's make a BitmapText actor that will output "Hello OutFox".
So, copy (or type) the following into the file.
return Def.ActorFrame{
Def.BitmapText{
Font="Common Normal",
Text="Hello OutFox!",
}
}
Now, save the file, and go back to the title screen. There are multiple ways of reloading your screen for testing, which will go over in a future chapter, but for now, restart the game and head back to the screen.
You'll see the text is there...! On the top left corner of the screen... what gives? Well, since we didn't specify any instructions to the BitmapText actor, it will just generate at the game's "origin point".
The origin point is effectively the default area where every actor will spawn at, if no instructions are given. So, let's move it somewhere else. For this, we'll use the On command to give this actor instructions.
After the line where it says Text="Hello OutFox!",
, type the following.
OnCommand=function(self)
self:Center()
end
Return to the Title Screen, and now the text is at the center of the screen!
But what about those instructions? What do they do?
What we've just added to the code is called a Command. These are, well... commands, that tell the actor what to do on a certain point in time.
In this case, we used the "On" command, which is run the moment the screen shows up. But there are another two present in the engine that are run automatically, "In", and "Begin".
The "In" command is run while the screen is loading, which is useful when you're setting up your actors. You should use this command to position them.
The "Begin" command is run after "On" has finished. think of it as a "I'm now ready to begin" command.
The order goes like this;
Now, inside that command we have functions, which are the actual instructions that the actor will perform. The actor, in each command is declared (usually) as self
. So, every function is called from self
.
Thus, in the example above, we called:
self:Center()
This tells the Bitmap actor, to run the Center()
function, which is available for every Actor, and its purpose is to place the actor on the center of the screen.
If you're curious of the equivalent of this function, it's using the
x
andy
functions to call the current center of the actor on the x and y axis.self:x(SCREEN_CENTER_X):y(SCREEN_CENTER_Y)
Do note that these three commands are not the only ones available; you can make your own custom commands! Which will be discussed on a later chapter.
Now that we created the actor, what is that overlay
bit on the filename?