miaoda-game-combat2d-phaser
v0.2.0
Published
Phaser 4 Scene host for miaoda-game-combat2d-core with Game Object-bound hitboxes and hurtboxes.
Downloads
493
Readme
miaoda-game-combat2d-phaser
Use this Phaser 4 adapter to bind combat boxes to Game Objects, synchronize their world positions, and deliver miaoda-game-combat2d-core hit events during Scene updates.
Install
pnpm add miaoda-game-combat2d-core miaoda-game-combat2d-phaser phaserCreate and bind a combat world
Register Combat2dPlugin as a Scene Plugin and create one world per independent arena:
const combat = this.combat2d.create({ defaultIframes: 6 });
combat.bindHurtbox(enemyHurtbox, enemy);
combat.bindHitbox(swordHitbox, player, { x: 30, y: 0 });
combat.onHit((hit) => applyDamage(hit.target, hit.damage));The adapter reads bound object positions before resolving each Scene update. defaultIframes counts logic frames. Objects with active === false or no Scene are unbound automatically.
Use an external physics broadphase
For large scenes, let Arcade or Matter produce candidate pairs and configure external resolution:
const combat = this.combat2d.create({ resolution: 'external' });
const contacts = collectPhysicsContacts();
// Once after the physics step in each logic frame:
combat.resolveContacts(contacts);External contacts still go through masks, attack deduplication, invincibility frames, and pierce limits. With resolution: 'external', the adapter does not also run its all-pairs geometry scan.
Lifecycle and control
combat.setTicking(false); // pause synchronization and resolution
combat.setTicking(true);
combat.remove('sword');
combat.core.resetAttack('swing-42');update receives Phaser milliseconds and ignores non-positive or non-finite values. destroy() is idempotent and terminal: it removes Scene listeners, bindings, callbacks, and boxes. The adapter reports accepted hits; your game decides damage, status effects, knockback, and presentation.
