VM_CAMERA_SET_POS
is a GBVM instruction used to immediately set the X and Y coordinates of the game camera to a new position.
Purpose: This instruction allows for instantaneous repositioning of the game camera without any smooth transition or interpolation. It is essential for:
When VM_CAMERA_SET_POS
is called, the camera’s view will instantly snap to the new coordinates in the very next frame, providing an immediate change in perspective.
Syntax:
VM_CAMERA_SET_POS X, Y
X
: The new X-coordinate (horizontal position) where the camera should be placed.Y
: The new Y-coordinate (vertical position) where the camera should be placed.Usage Example: Setting Camera After Player Teleportation
Imagine your player character steps on a warp tile that teleports them to a completely different section of the map. The camera should instantly follow the player to their new location.
; In your script, after the player is teleported:
; Assume PLAYER_ACTOR_ID is the actor ID for the player
PLAYER_ACTOR_ID:
.R_INT8 0 ; Example Actor ID
; Define the warp destination coordinates for the player
WARP_DEST_PLAYER_X:
.R_INT16 160 ; Example X-coordinate for player
WARP_DEST_PLAYER_Y:
.R_INT16 128 ; Example Y-coordinate for player
; ... code for warp tile detection and player teleportation ...
PLAYER_WARPED_ROUTINE:
; First, teleport the player actor to the new position
VM_ACTOR_SET_POS PLAYER_ACTOR_ID, WARP_DEST_PLAYER_X, WARP_DEST_PLAYER_Y
; Now, instantly set the camera's position to match the player's new location
; (Assuming camera should center on player, adjust X/Y for screen offset if needed)
VM_CAMERA_SET_POS WARP_DEST_PLAYER_X, WARP_DEST_PLAYER_Y
VM_LOAD_TEXT TEXT_WARPED_INSTANT
VM_DISPLAY_TEXT
VM_IDLE 60 ; Display message for a second
VM_RET
TEXT_WARPED_INSTANT:
.TEXT "You instantly warped!"
.TEXT_END
In this example, after VM_ACTOR_SET_POS
moves the player, VM_CAMERA_SET_POS WARP_DEST_PLAYER_X, WARP_DEST_PLAYER_Y
immediately snaps the camera to the same coordinates. This ensures that the player’s new location is instantly visible without any jarring camera movement or delay.
Analogy to other programming languages/game engines:
This is analogous to directly setting the position
property of a camera object in a game engine:
Camera.main.transform.position = new Vector3(x, y, z);
get_node("Camera2D").position = Vector2(x, y);
It provides direct, instantaneous control over the camera’s spatial location, which is fundamental for managing the player’s view of the game world.