njin
Engine 2D gọn nhẹ để tự tay làm game theo ý mình. Vibe coding cũng ổn luôn
Loading...
Searching...
No Matches
Video

Phát video MPEG-1 có tiếng: cutscene toàn màn hình, màn hình trong thế giới 3D. Tiếp...

Classes

struct  njin::video_desc
 Cách mở một video bằng video_open(). Tiếp...

Các hàm

video_handle njin::video_open (context &ctx, const video_desc &desc)
 Mở một video.
void njin::video_close (context &ctx, video_handle handle)
 Đóng video, giải phóng texture và tiếng của nó.
void njin::video_play (context &ctx, video_handle handle)
 Phát tiếp (hoặc phát lại từ đầu nếu đã hết).
void njin::video_pause (context &ctx, video_handle handle)
 Tạm dừng; hình đứng ở frame hiện tại.
bool njin::video_playing (const context &ctx, video_handle handle)
 Video có đang phát không.
bool njin::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 njin::video_seek (context &ctx, video_handle handle, f32 seconds)
 Nhảy tới giây seconds.
f32 njin::video_time (const context &ctx, video_handle handle)
 Đang ở giây thứ mấy.
f32 njin::video_duration (const context &ctx, video_handle handle)
 Video dài bao nhiêu giây.
void njin::video_set_loop (context &ctx, video_handle handle, bool loop)
 Bật tắt phát lặp.
void njin::video_set_volume (context &ctx, video_handle handle, f32 volume)
 Đặt âm lượng riêng của video, 0..1.
vec2 njin::video_size (const context &ctx, video_handle handle)
 Cỡ hình, pixel.
f32 njin::video_framerate (const context &ctx, video_handle handle)
 Số frame hình mỗi giây của file.
bool njin::video_has_audio (const context &ctx, video_handle handle)
 Video có phát tiếng không: file có tiếng, video_desc::audio bật và máy có thiết bị âm thanh.
i32 njin::video_frame_count (const context &ctx, video_handle handle)
 Số frame hình đã hiện kể từ khi mở (tăng cả khi tua): để biết hình đã đổi chưa.
texture_handle njin::video_texture (const context &ctx, video_handle handle)
 Texture chứa frame hình hiện tại.
void njin::video_draw (const context &ctx, video_handle handle, rect dest, rgba tint={1.0f, 1.0f, 1.0f, 1.0f})
 Vẽ frame hiện tại co giãn vào dest (2D, như texture_draw_ex()).
void njin::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 (dải đen của cutscene toàn màn hình).

Mô tả chi tiết

Phát video MPEG-1 có tiếng: cutscene toàn màn hình, màn hình trong thế giới 3D.

Thông tin về hàm

◆ video_open()

video_handle njin::video_open ( context & ctx,
const video_desc & desc )

Mở một video.

Engine giải mã nó trong phase_post_update theo thời gian thật (không theo time_set_scale(), vẫn chạy khi game pause), hình và tiếng khớp nhau. Mỗi frame hình mới được chép vào texture của video (video_texture()).

Các tham số
ctxContext của engine.
descCách mở.
Giá trị trả về
Handle, hoặc handle không hợp lệ nếu file thiếu hay không phải MPEG-1 (cảnh báo nói vì sao).

◆ video_close()

void njin::video_close ( context & ctx,
video_handle handle )

Đóng video, giải phóng texture và tiếng của nó.

Handle không hợp lệ bị bỏ qua.

Các tham số
ctxContext của engine.
handleVideo.

◆ video_play()

void njin::video_play ( context & ctx,
video_handle handle )

Phát tiếp (hoặc phát lại từ đầu nếu đã hết).

Các tham số
ctxContext của engine.
handleVideo.

◆ video_pause()

void njin::video_pause ( context & ctx,
video_handle handle )

Tạm dừng; hình đứng ở frame hiện tại.

Các tham số
ctxContext của engine.
handleVideo.

◆ video_playing()

bool njin::video_playing ( const context & ctx,
video_handle handle )

Video có đang phát không.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
true nếu đang phát.

◆ video_finished()

bool njin::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.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
true nếu đã hết.

◆ video_seek()

void njin::video_seek ( context & ctx,
video_handle handle,
f32 seconds )

Nhảy tới giây seconds.

Hình hiện ngay là frame gần nhất trước chỗ đó.

Các tham số
ctxContext của engine.
handleVideo.
secondsThời điểm, giây, kẹp trong 0..video_duration().

◆ video_time()

f32 njin::video_time ( const context & ctx,
video_handle handle )

Đang ở giây thứ mấy.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Thời điểm, giây.

◆ video_duration()

f32 njin::video_duration ( const context & ctx,
video_handle handle )

Video dài bao nhiêu giây.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Thời lượng, giây.

◆ video_set_loop()

void njin::video_set_loop ( context & ctx,
video_handle handle,
bool loop )

Bật tắt phát lặp.

Các tham số
ctxContext của engine.
handleVideo.
loopLặp.

◆ video_set_volume()

void njin::video_set_volume ( context & ctx,
video_handle handle,
f32 volume )

Đặt âm lượng riêng của video, 0..1.

Các tham số
ctxContext của engine.
handleVideo.
volumeÂm lượng.

◆ video_size()

vec2 njin::video_size ( const context & ctx,
video_handle handle )

Cỡ hình, pixel.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Rộng và cao.

◆ video_framerate()

f32 njin::video_framerate ( const context & ctx,
video_handle handle )

Số frame hình mỗi giây của file.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Frame mỗi giây.

◆ video_has_audio()

bool njin::video_has_audio ( const context & ctx,
video_handle handle )

Video có phát tiếng không: file có tiếng, video_desc::audio bật và máy có thiết bị âm thanh.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
true nếu có tiếng.

◆ video_frame_count()

i32 njin::video_frame_count ( const context & ctx,
video_handle handle )

Số frame hình đã hiện kể từ khi mở (tăng cả khi tua): để biết hình đã đổi chưa.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Số frame.

◆ video_texture()

texture_handle njin::video_texture ( const context & ctx,
video_handle handle )

Texture chứa frame hình hiện tại.

Vẽ nó như mọi texture (texture_draw_ex()), hay dán lên hình 3D (material3d::texture, model_material): màn hình TV, bảng quảng cáo. Texture thuộc về video: đừng texture_unload() nó; video_close() giải phóng.

Các tham số
ctxContext của engine.
handleVideo.
Giá trị trả về
Texture, hoặc handle không hợp lệ nếu video không hợp lệ.

◆ video_draw()

void njin::video_draw ( const context & ctx,
video_handle handle,
rect dest,
rgba tint = {1.0f, 1.0f, 1.0f, 1.0f} )

Vẽ frame hiện tại co giãn vào dest (2D, như texture_draw_ex()).

Các tham số
ctxContext của engine.
handleVideo.
destVùng vẽ.
tintMàu nhân vào hình.

◆ video_draw_fit()

void njin::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 (dải đen của cutscene toàn màn hình).

Các tham số
ctxContext của engine.
handleVideo.
areaVùng, thường là cả màn hình.
barsMàu dải thừa; trong suốt là không tô.