Viewport#
Variables#
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
int |
|
const int |
|
const int |
Functions#
void |
|
bool |
|
bool |
Contains(int x, int y) |
Enumerations#
enum ViewportMode: π Source
Added in version 3.0.
ViewportMode VIEW_MODE_CENTER_AND_BOUND = 0L
Position the viewport such that the Viewport::Target is in the middle of it (but bounded by the edges of the current region).
ViewportMode VIEW_MODE_CENTER = 1L
Position the viewport such that the Viewport::Target is in the middle of it, always. Screens outside the current region are rendered as black.
ViewportMode VIEW_MODE_SCRIPT = 2L
Disable the engineβs updating of the viewport on every frame, and instead defer to values set by scripts.
Variable descriptions#
ViewportMode Mode π Source
Added in version 3.0.
Defaults to VIEW_MODE_CENTER_AND_BOUND, and is reset at the beginning of scrolling.
Added in version 3.0.
The sprite that the viewport is centered around. If this sprite no longer exists, this will be reset to the Hero sprite.
Defaults to Hero, and is reset at the beginning of scrolling.
Added in version 3.0.
Width of the viewport deadzone box, in pixels (0 to 240). While the Targetβs center (shifted by any LookaheadX/LookaheadY offset) stays within this box, which is centered on the viewportβs focus point (its center, except where a region edge stops the viewport), the viewport does not move horizontally; once it pushes past an edge of the box, the viewport moves just enough to keep it on the edge.
0 keeps the viewport locked to the target, which is the default for quests made before this setting existed; new quests start with a 32 by 32 box. Only observable in scrolling regions. One of the follow settings; see the class notes for how it is configured and reset.
int DeadzoneHeight π Source
Added in version 3.0.
Height of the viewport deadzone box, in pixels (0 to 160). See DeadzoneWidth.
Added in version 3.0.
How far the viewport aims ahead of the direction the Target is moving horizontally, in pixels (-128 to 127). Positive values lead in front of the target (more frontal view); negative values trail behind it. Each axis has its own distance (see LookaheadY), so diagonal movement leads by both.
While the target moves, the offset shifts toward the lead at LookaheadSpeed pixels per frame (easing out on an axis it isnβt moving along). Movement against the direction the target faces is ignored, so being knocked back, or pushed backward by a conveyor or a script, doesnβt swing the viewport; sideways movement still counts. While it stands still, the offset holds, so the viewport never drifts or reacts to turning in place. Warps (whistle warps included), camera cutscene effects and setting Mode back from VIEW_MODE_SCRIPT drop the offset (it rebuilds as the target moves); scroll transitions carry it. Only observable in scrolling regions.
The offset the viewport actually holds is capped on each axis so the viewport can still reach the region edges: 120 - DeadzoneWidth/2 horizontally, and 80 - DeadzoneHeight/2 vertically.
One of the follow settings; see the class notes for how it is configured and reset.
Added in version 3.0.
How far the viewport aims ahead of the direction the Target is moving vertically, in pixels (-128 to 127). See LookaheadX. Since the viewport is shorter than it is wide, a smaller distance usually feels right here.
In sideview, jumping and falling count as vertical movement, so a jump shifts the viewport too. To keep jumps from moving it, set this to 0 on sideview dmaps (see DMFS_CUSTOM_VIEWPORT_FOLLOW).
int LookaheadSpeed π Source
Added in version 3.0.
How fast the LookaheadX/LookaheadY offset shifts, in pixels per frame (0 to 240; 0 freezes the current offset in place). Fractional values are allowed, and values between 0 and 1 are recommended: while the target moves this speed is added to their own, so anything higher makes the viewport visibly outrun them.
1 unless changed. One of the follow settings; see the class notes for how it is configured and reset.
Added in version 3.0.
Idle recentering: once the Target has stood still for RecenterDelay frames, the viewport eases back toward it at this many pixels per frame (0 to 240, fractional) until it is centered again. A held LookaheadX/LookaheadY offset still applies: the viewport moves toward the target only as far as the deadzone box allows, and never further ahead. 0 (the default) disables it; any movement cancels it. Only observable in scrolling regions with a deadzone.
One of the follow settings; see the class notes for how it is configured and reset.
Added in version 3.0.
How many frames the Target must stand still before idle recentering (see RecenterSpeed) begins (0 to 65535; 30 unless changed).
One of the follow settings; see the class notes for how it is configured and reset.
Unless Mode is VIEW_MODE_SCRIPT, this is updated every frame by the engine.
Unless Mode is VIEW_MODE_SCRIPT, this is updated every frame by the engine.
Function descriptions#
void ResetFollowSettings() π Source
Added in version 3.0.
Restores the follow settings (DeadzoneWidth, DeadzoneHeight, LookaheadX, LookaheadY, LookaheadSpeed, RecenterSpeed and RecenterDelay) to their configured values, discarding any values written by scripts.
bool Contains(sprite s) π Source
Added in version 3.0.
Returns true if the given sprite is visible within the viewport.
Note: this function ignores the fact that the bottom 8 pixels may not be visible given qr_HIDE_BOTTOM_8_PIXELS.
bool Contains(int x, int y) π Source
Added in version 3.0.
Returns true if the given point is visible within the viewport.
Note: this function ignores the fact that the bottom 8 pixels may not be visible given qr_HIDE_BOTTOM_8_PIXELS.
Added in version 2.55.9: Basic, read-only access
Changed in version 3.0: Full access via Viewport->Mode
Defines the visible portion of the current Region - aka, what the player currently sees.
For an example usage, see: ZQuestClassic/ZQuestClassic
Access with
Viewport->.The *follow settings* (DeadzoneWidth, DeadzoneHeight, LookaheadX, LookaheadY, LookaheadSpeed, RecenterSpeed and RecenterDelay) control how the viewport follows its Target in scrolling regions. Each defaults to the value configured for the current dmap (if it has DMFS_CUSTOM_VIEWPORT_FOLLOW) or in the editorβs Init Data, on the Vars > Regions tab; writing to one overrides that until ResetFollowSettings() is called or the game is restarted or continued. Unlike Mode and Target, they are NOT reset by scrolling or by camera cutscene effects.