Application Version
Current version of TyranoBuilder Next as of now 2.4.7
Download the application and modifications only from this site. The author is not responsible for the application or modifications downloaded from other sources.
The source code is open, so anyone can make changes to the code that may harm your device.
- Difficulty: Light
Actually, there is nothing complicated here. To implement this behavior, we need a variable and a branching system.
The variable is created in the variable manager.
You can name a variable anything you like, e.g. bg_. Name variables to your liking to make them easier for you to understand! The variable must be a system variable, so that its value is not lost after the game is restarted. Therefore, when creating a variable, you need to toggle the "System Variable" switch (by default, the switch is in the "disabled" position).
Next, we need to assign a value to the variable. In my example I do this at game startup, but this way you can only initialize the variable, and then the value will be overwritten each time the game starts. That's why you should not do it this way, it is suitable only for testing. In a real game you need to change the value at the right moment.
All variables have been created and their values have been written. Now let's move on to creating the conditions under which we will display different material. For this purpose, we will use the branching system. This system is very simple and has only four components.
Condition Start: A mandatory component, it is placed first and specifies the condition to be met.
Additional condition: As the name implies, this is an additional condition. It will be triggered if the condition specified in Condition Start is not triggered.
Otherwise: Will only work if none of the conditions above work.
Condition end: The mandatory component is placed the very last. It is needed to close the condition block.
Now let's place the components we need on the stage and make the background change at a certain value of the variable.
You can change any component, not just the background as I did.
For Condition Start, I specify the following code:
sf.bg_==0
Which means the following - if the system variable (sf) bg_ is 0, we do the very first action and ignore the Additional condition as well as Otherwise.
But we want to make different backgrounds depending on the variable, right? Then we need Otherwise. We are going to change the background only once, so Otherwise is fine, but if there are more variations, we need an Additional condition where we can set for example this condition:
sf.bg_<=0
This condition will work only if the value of the gb_ variable is less than or equal to 0.
You can read more about conditions and branching here.
In the picture you can see how I arranged the components in the scene. The logic here is simple: anything above Otherwise but before Condition Start will be executed if the first condition is triggered. This means that this is where we place the components we need for the first condition. After Otherwise, we place the components that are needed if the first condition does not work.
Here's what the end result will look like: