VM_ACTOR_SET_HIDDEN
is a GBVM instruction used to control the visibility of a specified actor, making it appear or disappear from the game screen.
Purpose:
Controlling actor visibility is a fundamental aspect of game design, allowing for dynamic environments, hidden elements, and scripted events. VM_ACTOR_SET_HIDDEN
is essential for:
When an actor is hidden, it is typically no longer rendered on screen, and its collision detection might also be disabled (depending on engine implementation). When shown, it becomes visible again and resumes its normal rendering and interaction properties.
Syntax:
VM_ACTOR_SET_HIDDEN ACTOR, HIDDEN
ACTOR
: A variable that contains the actor number (ID) of the actor whose visibility you want to change.HIDDEN
: A constant that specifies the desired visibility state:
.ACTOR_VISIBLE
: Makes the actor visible..ACTOR_HIDDEN
: Makes the actor hidden.Usage Example: Making a Secret Item Appear After a Puzzle
Imagine a secret treasure chest that only appears after the player solves a specific puzzle. You can initially keep the chest hidden and then reveal it using VM_ACTOR_SET_HIDDEN
.
; In your script:
; Assume SECRET_CHEST_ACTOR_ID is the actor ID for the secret chest
SECRET_CHEST_ACTOR_ID:
.R_INT8 50 ; Example Actor ID
; Assume VAR_PUZZLE_SOLVED is a flag (0 = unsolved, 1 = solved)
VAR_PUZZLE_SOLVED:
.R_INT8 0
; Initially, hide the secret chest (e.g., in scene initialization)
VM_ACTOR_SET_HIDDEN SECRET_CHEST_ACTOR_ID, .ACTOR_HIDDEN
; ... code for puzzle logic ...
; When the puzzle is solved:
PUZZLE_SOLVED_ROUTINE:
VM_SET_CONST VAR_PUZZLE_SOLVED, 1
; Show the secret chest
VM_ACTOR_SET_HIDDEN SECRET_CHEST_ACTOR_ID, .ACTOR_VISIBLE
VM_LOAD_TEXT TEXT_SECRET_CHEST_APPEARS
VM_DISPLAY_TEXT
VM_IDLE 60 ; Display message for a second
VM_RET
TEXT_SECRET_CHEST_APPEARS:
.TEXT "A secret chest appeared!"
.TEXT_END
; Visibility constants (these would be defined globally)
.ACTOR_VISIBLE:
.R_INT8 0
.ACTOR_HIDDEN:
.R_INT8 1
In this example, VM_ACTOR_SET_HIDDEN SECRET_CHEST_ACTOR_ID, .ACTOR_HIDDEN
initially makes the chest invisible. Once the PUZZLE_SOLVED_ROUTINE
is triggered, VM_ACTOR_SET_HIDDEN SECRET_CHEST_ACTOR_ID, .ACTOR_VISIBLE
makes the chest appear on screen, allowing the player to interact with it. This provides a clear visual reward for solving the puzzle.
Analogy to other programming languages/game engines:
This is directly analogous to setting the visible
or enabled
property of a game object or sprite:
gameObject.SetActive(true/false);
node.visible = true/false;
display: none;
or visibility: hidden;
for an element.It provides a straightforward way to toggle the visual presence of actors in your game world.