跳到主要内容

Class: ScreenDisplay

Contains information about user interface elements that are showing up on the screen.

Examples

import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe((event) => {
event.player.onScreenDisplay.setTitle('§o§6You respawned!§r');
});
import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe((event) => {
event.player.onScreenDisplay.setTitle('You respawned', {
stayDuration: 100,
fadeInDuration: 2,
fadeOutDuration: 4,
subtitle: 'Try not to die next time!',
});
});
import { world, system } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe(event => {
event.player.onScreenDisplay.setTitle('Get ready!', {
stayDuration: 220,
fadeInDuration: 2,
fadeOutDuration: 4,
subtitle: '10',
});

let countdown = 10;

const intervalId = system.runInterval(() => {
countdown--;
event.player.onScreenDisplay.updateSubtitle(countdown.toString());

if (countdown == 0) {
system.clearRun(intervalId);
}
}, 20);
});

Constructors

new ScreenDisplay()

private new ScreenDisplay(): ScreenDisplay

Returns

ScreenDisplay

Methods

getHiddenHudElements()

Beta

getHiddenHudElements(): HudElement[]

Returns

HudElement[]

Remarks

This function can't be called in read-only mode.

Throws

This function can throw errors.


hideAllExcept()

Beta

hideAllExcept(hudElements?): void

Parameters

ParameterType
hudElements?HudElement[]

Returns

void

Remarks

This function can't be called in read-only mode.

Throws

This function can throw errors.


isForcedHidden()

Beta

isForcedHidden(hudElement): boolean

Parameters

ParameterType
hudElementHudElement

Returns

boolean

Remarks

This function can't be called in read-only mode.

Throws

This function can throw errors.


isValid()

isValid(): boolean

Returns

boolean

Remarks

Returns true if the current reference to this screen display manager object is valid and functional.


resetHudElements()

Beta

resetHudElements(): void

Returns

void

Remarks

This function can't be called in read-only mode.

Throws

This function can throw errors.


setActionBar()

setActionBar(text): void

Parameters

ParameterTypeDescription
textstring | RawMessage | (string | RawMessage)[]New value for the action bar text.

Returns

void

Remarks

Set the action bar text - a piece of text that displays beneath the title and above the hot-bar.

This function can't be called in read-only mode.

Throws

This function can throw errors.


setHudVisibility()

Beta

setHudVisibility(visible, hudElements?): void

Parameters

ParameterType
visibleHudVisibility
hudElements?HudElement[]

Returns

void

Remarks

This function can't be called in read-only mode.

Throws

This function can throw errors.


setTitle()

setTitle(title, options?): void

Parameters

ParameterType
titlestring | RawMessage | (string | RawMessage)[]
options?TitleDisplayOptions

Returns

void

Remarks

Will cause a title to show up on the player's on screen display. Will clear the title if set to empty string. You can optionally specify an additional subtitle as well as fade in, stay and fade out times.

This function can't be called in read-only mode.

Throws

This function can throw errors.

Examples

import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe((event) => {
event.player.onScreenDisplay.setTitle('§o§6You respawned!§r');
});
import { world } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe((event) => {
event.player.onScreenDisplay.setTitle('You respawned', {
stayDuration: 100,
fadeInDuration: 2,
fadeOutDuration: 4,
subtitle: 'Try not to die next time!',
});
});
import { world, system } from '@minecraft/server';

world.afterEvents.playerSpawn.subscribe(event => {
event.player.onScreenDisplay.setTitle('Get ready!', {
stayDuration: 220,
fadeInDuration: 2,
fadeOutDuration: 4,
subtitle: '10',
});

let countdown = 10;

const intervalId = system.runInterval(() => {
countdown--;
event.player.onScreenDisplay.updateSubtitle(countdown.toString());

if (countdown == 0) {
system.clearRun(intervalId);
}
}, 20);
});

updateSubtitle()

updateSubtitle(subtitle): void

Parameters

ParameterType
subtitlestring | RawMessage | (string | RawMessage)[]

Returns

void

Remarks

Updates the subtitle if the subtitle was previously displayed via the setTitle method.

This function can't be called in read-only mode.

Throws

This function can throw errors.