Trang này phát video trong game: cutscene đầu màn, đoạn phim kết thúc, màn hình TV hay bảng quảng cáo trong thế giới 3D. Mọi thứ khai báo trong njin_video.h; giải mã bằng pl_mpeg, nằm trong engine.
bool video_finished(const context &ctx, video_handle handle)
Video đã phát hết chưa (không lặp và đã đến cuối): lúc chuyển cảnh sau cutscene.
void video_draw_fit(const context &ctx, video_handle handle, rect area, rgba bars={0.0f, 0.0f, 0.0f, 1.0f})
Vẽ frame hiện tại vừa khít trong area, giữ tỉ lệ khung hình: phần thừa hai bên hay trên dưới tô bars ...
video_handle video_open(context &ctx, const video_desc &desc)
Mở một video.
vec2 window_size(const context &ctx)
Kích thước thật của cửa sổ, pixel, kể cả khi có độ phân giải ảo.
Định danh của một video, mở bởi video_open().
Definition _types.h:293
| Hàm | Làm gì |
| video_play(), video_pause() | Phát tiếp, tạm dừng. Phát một video đã hết thì phát lại từ đầu |
| video_seek() | Nhảy tới một giây (hình hiện là frame gần nhất trước chỗ đó) |
| video_set_loop(), video_set_volume() | Lặp, âm lượng riêng |
| video_time(), video_duration(), video_finished() | Đang ở đâu, dài bao lâu, đã hết chưa |
| video_size(), video_framerate(), video_has_audio() | Cỡ hình, frame mỗi giây, có tiếng không |
| video_close() | Đóng, giải phóng hình và tiếng |
Cutscene toàn màn hình, Enter để bỏ qua; xong thì vào một căn phòng có TV phát một video lặp.
#include <njin.h>
namespace {
using namespace njin;
bool playing_intro = true;
void load(context &ctx) {
intro =
video_open(ctx, {.path =
"videos/intro.mpg"});
tv =
video_open(ctx, {.path =
"videos/news.mpg", .loop =
true, .play =
false, .bus =
bus_sfx, .volume = 0.4f});
}
void update(context &ctx) {
if (!playing_intro)
return;
playing_intro = false;
}
}
void render(context &ctx) {
if (playing_intro) {
return;
}
begin_3d(ctx,
camera3d{.position = {0.0f, 1.6f, 4.0f}, .target = {0.0f, 1.2f, 0.0f}});
draw_cube3d(ctx, {0.0f, 0.4f, 0.0f}, {2.2f, 0.8f, 0.6f},
rgba{0.3f, 0.2f, 0.15f, 1.0f});
}
void setup(context &ctx) {
}
}
mod_desc cinema_module() {
return {.name =
"cinema", .setup = setup}; }
void material3d_set(context &ctx, const material3d &material)
Đặt bề mặt cho các hình 3D vẽ sau lệnh này, đến lần gọi tiếp theo hoặc end_3d().
void begin_3d(context &ctx, const camera3d &camera)
Bắt đầu vẽ 3D qua camera.
void draw_cube3d(const context &ctx, vec3 center, vec3 size, rgba color)
Vẽ hộp đặc, các cạnh song song với trục.
void end_3d(context &ctx)
Kết thúc vẽ 3D và quay về vẽ 2D trong không gian thế giới.
void ecs_register(context &ctx, sys_phase phase, sys_fnc fnc, const char *name=nullptr)
Thêm một system vào lịch chạy của một phase.
@ phase_update
Mỗi frame, logic chính của game.
Definition _mod.h:35
@ phase_startup
Một lần, trước frame đầu tiên.
Definition _mod.h:32
@ phase_render
Mỗi frame, vẽ trong không gian thế giới.
Definition _mod.h:38
@ bus_sfx
Hiệu ứng trong game. Mặc định của sound.
Definition njin_audio.h:20
void video_play(context &ctx, video_handle handle)
Phát tiếp (hoặc phát lại từ đầu nếu đã hết).
void video_close(context &ctx, video_handle handle)
Đóng video, giải phóng texture và tiếng của nó.
texture_handle video_texture(const context &ctx, video_handle handle)
Texture chứa frame hình hiện tại.
constexpr rgba white
Trắng.
Definition _math.h:234
Camera phối cảnh cho begin_3d().
Definition njin_3d.h:15
Bề mặt của các hình 3D vẽ sau material3d_set().
Definition njin_3d.h:143
bool unlit
Bỏ qua ánh sáng, giữ nguyên màu (vệt đạn, tia laze, UI trong thế giới).
Definition njin_3d.h:152
Mô tả một module: một nhóm system có tên.
Definition _mod.h:67
Màu gồm đỏ, xanh lá, xanh dương và alpha.
Definition _types.h:64