Capture
Volver a la referencia

Capture

Photos of the game taken by the game: a region or a box, with or without screen effects, and what each photo shows.

6 símbolos

useCapturefunctionhooknacatamalon

useCapture() => TCapture

A camera for the game itself: takes photos of what the player sees, the whole screen or a part of it, for a photography game, an album, a "spot the difference", a sticker of the boss beaten. Call it in a scene's body or a behaviour's, and take a photo at any moment after (it resolves the next frame, drawn once more for it, so it is for taking a picture, not for every frame).

A photo is pixels, plus what came out in it (boxes): each box shown in the frame, how much of it (seen, 0 to 1) and where, for scoring what the player took a picture of. To show it, make the print in the scene's body (createPixels, createPixelTexture, a sprite with it), then copy each photo into it and updatePixelTexture; a build script saves one with encodePng.

  • region: a rectangle of the screen in the game's pixels, or a box (or its name), the part of the screen it covers, measured even hidden: a viewfinder that is never drawn.
  • hide: boxes left out (the HUD, the touch pad), by box or by name.
  • only: the only boxes in it, on a transparent background: one thing alone.
  • width, height: the photo's size, by whole pixels, never smoothed.
  • effects: false: under the screen effects, as the scene is drawn.

Works while the game is paused. Two photos asked for at once are taken one after the other.

Ejemplo

const capture = useCapture();
const shutter = useAction('shoot');
// The print the last photo shows on, made once in the body.
const film = createPixels(96, 72);
const print = createPixelTexture(film);
createSprite({ texture: print, transform: { x: 270, y: 50 } });
let score = 0;

useUpdate(() => {
    if (shutter.justPressed()) {
        void capture({ region: 'Viewfinder', hide: ['Hud'], width: 96, height: 72 }).then((photo) => {
            const bird = photo.boxes.find((b) => b.name === 'Bird');
            score += bird ? Math.round(bird.seen * 100) : 0;
            film.data.set(photo.data);
            updatePixelTexture(print);
        });
    }
});
Ver el código · hooks/capture/use_capture.ts:54

TPhototypenacatamalon

TPhoto: TPixels & { boxes }

A photo: its pixels, which show (createPixelTexture) or save (encodePng) as any picture painted in code, and what came out in it, most seen first.

Propiedades

boxestypeOperator
type'pixels'
widthnumber
heightnumber
dataUint8Array
Ver el código · capture/types/t_photo.ts:99

TPhotoBoxtypenacatamalon

Something that came out in a photo: how much of it, and where. For telling what a player took a picture of: the bird is in it, most of it, in the middle.

Each sprite, text and panel shown is one, measured by its rectangle turned as it is drawn; a box with hitboxes is one, measured by them (what it is to be hit is what it is to be photographed). Something covered by another is still in the photo by this measure, and a model in depth is not listed.

Propiedades

boxTBox

The box it is, or is in.

pictureTSprite | TText | TNineSlice

What it draws that came out: the sprite, text or panel (as createSprite gave it).

namestring

Its box's name.

seennumber

How much of it is inside the photo, from 0 to 1: 1 all of it, 0.5 half.

xnumber

The middle of what of it is inside, in the photo's own pixels.

ynumber
Ver el código · capture/types/t_photo.ts:73

TPhotoBoxReftypenacatamalon

TPhotoBoxRef: TBox | TSprite | TText | TNineSlice | string

Something named in a photo's options: a box, what it draws (a sprite, a text or a panel, as createSprite gave it), or a box's name, which stands for every box of the running scenes called that ('Hud'), the way a behaviour finds the others.

Ver el código · capture/types/t_photo.ts:16

TPhotoOptionstypenacatamalon

What a photo is of (useCapture). Nothing at all is the screen as the player sees it.

Propiedades

regionopcionalTPixelRegion | TPhotoBoxRef

The part of the screen it is of: a rectangle in the game's pixels ({ x, y, width, height } from the screen's top-left corner), or a box, the part of the screen it covers. A box is measured as collisionBetween measures it, by its hitboxes or else by what it draws, and is measured hidden too: a viewfinder can be a box that is never shown. Default: the whole screen.

hideopcionaltypeOperator

Boxes left out of the photo, with everything in them: the HUD, the touch pad, the viewfinder's frame.

onlyopcionaltypeOperator

The only boxes in the photo, with everything in them, on a transparent background unless background says otherwise: a picture of one thing alone, for an album or a sticker.

widthopcionalnumber

How big the photo comes out, in pixels. Made smaller or bigger by whole pixels, never smoothed, as pixel art is. Left out, the region's own size; one of the two given, the other keeps its shape.

heightopcionalnumber
effectsopcionalboolean

Whether the screen effects (a CRT, a palette, a dither) are in it, as the player sees them. Default true; false for the scene as it is drawn, under them.

backgroundopcional{ r, g, b, a }

What is behind everything. Default the game's background, or transparent with only.

Ver el código · capture/types/t_photo.ts:25