Skip to main content

CooldownBehavior

@zylem/game-lib


@zylem/game-lib / behavior / CooldownBehavior

Variable: CooldownBehavior

const CooldownBehavior: BehaviorDescriptor<CooldownOptions, CooldownHandle, unknown>

Defined in: node_modules/.pnpm/@zylem+behaviors@0.8.9_@types+react@19.3.0_react@19.3.0_three@0.185.1/node_modules/@zylem/behaviors/dist/cooldown.d.ts:65

CooldownBehavior

Example​

import { CooldownBehavior } from '@zylem/game-lib/behavior';
import { moveBy } from '@zylem/game-lib/actions';

const hero = createBox({ ... });
const cd = hero.use(CooldownBehavior, {
cooldowns: {
attack: { duration: 5 },
dash: { duration: 2, immediate: false },
},
});

hero.onUpdate(({ me, inputs }) => {
if (cd.isReady('attack') && inputs.p1.buttons.A.pressed) {
cd.fire('attack');
// perform attack
}
if (cd.isReady('dash') && inputs.p1.buttons.B.pressed) {
cd.fire('dash');
me.runAction(moveBy({ x: 10, duration: 0.3 }));
}
});