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
Hẹn giờ và tween theo entity

Chạy hàm sau một khoảng, lặp lại, và chuyển vị trí, tỉ lệ, màu của entity mượt mà. Tiếp...

Classes

struct  njin::timer_handle
 Định danh của một hẹn giờ, từ timer_after() hoặc timer_every(). Tiếp...
struct  njin::tween_handle
 Định danh của một tween chạy trên entity, từ tween_move() và các hàm cùng họ. Tiếp...
struct  njin::timer_desc
 Tùy chọn của một hẹn giờ. Tiếp...
struct  njin::tween_desc
 Tùy chọn của một tween. Tiếp...

Các hàm

timer_handle njin::timer_after (context &ctx, f32 seconds, std::function< void(context &)> fn, const timer_desc &desc={})
 Gọi fn một lần sau seconds giây.
timer_handle njin::timer_every (context &ctx, f32 interval, std::function< void(context &)> fn, i32 count=-1, const timer_desc &desc={})
 Gọi fn mỗi interval giây: sinh quái theo nhịp, hồi máu từ từ.
void njin::timer_cancel (context &ctx, timer_handle timer)
 Hủy một hẹn giờ.
bool njin::timer_active (const context &ctx, timer_handle timer)
 Hẹn giờ còn đang chờ không.
tween_handle njin::tween_move (context &ctx, entt::entity entity, vec2 to, f32 seconds, ease curve=ease::out_quad, const tween_desc &desc={})
 Dời transform.pos của entity tới to trong seconds giây.
tween_handle njin::tween_scale (context &ctx, entt::entity entity, f32 to, f32 seconds, ease curve=ease::out_quad, const tween_desc &desc={})
 Đổi transform.scale của entity tới to.
tween_handle njin::tween_rotate (context &ctx, entt::entity entity, f32 to, f32 seconds, ease curve=ease::out_quad, const tween_desc &desc={})
 Xoay transform.rot của entity tới to độ.
tween_handle njin::tween_tint (context &ctx, entt::entity entity, rgba to, f32 seconds, ease curve=ease::linear, const tween_desc &desc={})
 Đổi sprite.tint của entity tới to (cả độ trong suốt).
tween_handle njin::tween_value (context &ctx, f32 from, f32 to, f32 seconds, std::function< void(context &, f32)> apply, ease curve=ease::linear, const tween_desc &desc={}, entt::entity owner=entt::null)
 Chạy một giá trị từ from tới to và đưa nó cho apply mỗi frame: tween cho bất cứ thứ gì (âm lượng, thanh máu hiện chậm, bán kính vòng nổ).
void njin::tween_cancel (context &ctx, tween_handle tween)
 Hủy một tween, giữ nguyên giá trị đang có.
void njin::tween_cancel_all (context &ctx, entt::entity entity)
 Hủy mọi tween đang chạy trên một entity.
bool njin::tween_active (const context &ctx, tween_handle tween)
 Tween còn đang chạy (kể cả đang chờ delay) không.

Mô tả chi tiết

Chạy hàm sau một khoảng, lặp lại, và chuyển vị trí, tỉ lệ, màu của entity mượt mà.

Thông tin về hàm

◆ timer_after()

timer_handle njin::timer_after ( context & ctx,
f32 seconds,
std::function< void(context &)> fn,
const timer_desc & desc = {} )

Gọi fn một lần sau seconds giây.

njin::timer_after(ctx, 0.4f, [](njin::context &c) { njin::scene_fade(c, next); });
njin::timer_after(ctx, 1.5f, respawn, {.owner = player});
void scene_fade(context &ctx, scene_handle scene, const scene_transition &transition={})
Chuyển sang scene khác với hiệu ứng mờ dần (fade).
timer_handle timer_after(context &ctx, f32 seconds, std::function< void(context &)> fn, const timer_desc &desc={})
Gọi fn một lần sau seconds giây.

Hàm chạy trong phase_update (trước system của game), nên được thêm, hủy entity và tạo hẹn giờ mới. Thời gian tính từ frame gọi hàm.

Các tham số
ctxContext của engine.
secondsThời gian chờ, giây. 0 là frame sau.
fnHàm cần gọi.
descTùy chọn.
Giá trị trả về
Handle để hủy bằng timer_cancel().

◆ timer_every()

timer_handle njin::timer_every ( context & ctx,
f32 interval,
std::function< void(context &)> fn,
i32 count = -1,
const timer_desc & desc = {} )

Gọi fn mỗi interval giây: sinh quái theo nhịp, hồi máu từ từ.

Các tham số
ctxContext của engine.
intervalKhoảng cách giữa hai lần gọi, giây. Lớn hơn 0.
fnHàm cần gọi.
countSố lần gọi, -1 là mãi mãi (đến khi timer_cancel()).
descTùy chọn.
Giá trị trả về
Handle để hủy bằng timer_cancel().

◆ timer_cancel()

void njin::timer_cancel ( context & ctx,
timer_handle timer )

Hủy một hẹn giờ.

Handle đã hết hạn hoặc không hợp lệ bị bỏ qua.

Các tham số
ctxContext của engine.
timerHẹn giờ.

◆ timer_active()

bool njin::timer_active ( const context & ctx,
timer_handle timer )

Hẹn giờ còn đang chờ không.

Các tham số
ctxContext của engine.
timerHẹn giờ.
Giá trị trả về
true nếu nó chưa chạy xong và chưa bị hủy.

◆ tween_move()

tween_handle njin::tween_move ( context & ctx,
entt::entity entity,
vec2 to,
f32 seconds,
ease curve = ease::out_quad,
const tween_desc & desc = {} )

Dời transform.pos của entity tới to trong seconds giây.

Mọi tween trên entity: bắt đầu từ giá trị hiện tại (lúc hết delay), tự hủy khi entity bị hủy, và thay thế tween cũ cùng loại trên cùng entity (gọi tween_move hai lần thì cái sau thắng). Chạy trong phase_update.

njin::tween_move(ctx, door, door_pos + njin::vec2{0, -32}, 0.6f, njin::ease::out_cubic);
njin::tween_scale(ctx, coin, 1.4f, 0.1f, njin::ease::out_quad, {.repeat = 1, .yoyo = true});
tween_handle tween_scale(context &ctx, entt::entity entity, f32 to, f32 seconds, ease curve=ease::out_quad, const tween_desc &desc={})
Đổi transform.scale của entity tới to.
tween_handle tween_move(context &ctx, entt::entity entity, vec2 to, f32 seconds, ease curve=ease::out_quad, const tween_desc &desc={})
Dời transform.pos của entity tới to trong seconds giây.
@ out_cubic
Giảm tốc mạnh.
Definition _tween.h:60
@ out_quad
Giảm tốc nhẹ.
Definition _tween.h:57
Vector 2 chiều. Dùng cho vị trí, kích thước, độ dời.
Definition _types.h:39
Các tham số
ctxContext của engine.
entityEntity có transform.
toVị trí đích.
secondsThời lượng.
curveĐường cong.
descTùy chọn.
Giá trị trả về
Handle để hủy bằng tween_cancel().

◆ tween_scale()

tween_handle njin::tween_scale ( context & ctx,
entt::entity entity,
f32 to,
f32 seconds,
ease curve = ease::out_quad,
const tween_desc & desc = {} )

Đổi transform.scale của entity tới to.

Xem tween_move().

Các tham số
ctxContext của engine.
entityEntity có transform.
toTỉ lệ đích.
secondsThời lượng.
curveĐường cong.
descTùy chọn.
Giá trị trả về
Handle.

◆ tween_rotate()

tween_handle njin::tween_rotate ( context & ctx,
entt::entity entity,
f32 to,
f32 seconds,
ease curve = ease::out_quad,
const tween_desc & desc = {} )

Xoay transform.rot của entity tới to độ.

Xem tween_move().

Các tham số
ctxContext của engine.
entityEntity có transform.
toGóc đích, độ.
secondsThời lượng.
curveĐường cong.
descTùy chọn.
Giá trị trả về
Handle.

◆ tween_tint()

tween_handle njin::tween_tint ( context & ctx,
entt::entity entity,
rgba to,
f32 seconds,
ease curve = ease::linear,
const tween_desc & desc = {} )

Đổi sprite.tint của entity tới to (cả độ trong suốt).

Xem tween_move().

Các tham số
ctxContext của engine.
entityEntity có njin::sprite.
toMàu đích.
secondsThời lượng.
curveĐường cong.
descTùy chọn.
Giá trị trả về
Handle.

◆ tween_value()

tween_handle njin::tween_value ( context & ctx,
f32 from,
f32 to,
f32 seconds,
std::function< void(context &, f32)> apply,
ease curve = ease::linear,
const tween_desc & desc = {},
entt::entity owner = entt::null )

Chạy một giá trị từ from tới to và đưa nó cho apply mỗi frame: tween cho bất cứ thứ gì (âm lượng, thanh máu hiện chậm, bán kính vòng nổ).

Các tham số
ctxContext của engine.
fromGiá trị đầu.
toGiá trị cuối.
secondsThời lượng.
applyNhận giá trị mỗi frame, kể cả giá trị cuối.
curveĐường cong.
descTùy chọn.
ownerEntity sở hữu: bị hủy thì tween dừng. Có thể để null.
Giá trị trả về
Handle.

◆ tween_cancel()

void njin::tween_cancel ( context & ctx,
tween_handle tween )

Hủy một tween, giữ nguyên giá trị đang có.

Không gọi done.

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

◆ tween_cancel_all()

void njin::tween_cancel_all ( context & ctx,
entt::entity entity )

Hủy mọi tween đang chạy trên một entity.

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

◆ tween_active()

bool njin::tween_active ( const context & ctx,
tween_handle tween )

Tween còn đang chạy (kể cả đang chờ delay) không.

Các tham số
ctxContext của engine.
tweenTween.
Giá trị trả về
true nếu còn chạy.