miaoda-game-juice-cocos
v0.3.1
Published
Game-feel ('juice') helpers for Cocos Creator: floating damage/heal numbers, hit-flash (tint a Sprite/Label to white and back), and a decaying screen/node shake you trigger on impact. Purely presentational — the small universal touches that make a hit fee
Maintainers
Readme
miaoda-game-juice-cocos
Presentational hit feedback for Cocos Creator: floating numbers, tint flashes, and deterministic screen shake. Choose it when gameplay already knows what happened and only needs a reusable visual response. It does not apply damage, invulnerability, knockback, score, or other game rules.
pnpm add miaoda-game-juice-cocosimport {Color} from 'cc';
import {ShakeComponent, hitFlash, spawnFloatingText} from 'miaoda-game-juice-cocos';
const shaker = cameraNode.addComponent(ShakeComponent);
spawnFloatingText(world, {text: '-7', x: enemy.x, y: enemy.y, color: new Color(240, 80, 80, 255)});
hitFlash(enemy);
shaker.medium();spawnFloatingText(parent, options) creates text that rises, fades, and removes itself. hitFlash(node, options?) temporarily changes a Sprite or Label tint and restores the previous color. Attach ShakeComponent to a camera or world root and call small(), medium(), large(), or shake(...).
For custom camera logic, shakeOffset({amplitude, duration, seed}, t) returns a deterministic {x, y} offset. Values and time must be finite; durations and positions cannot be negative where the API disallows them. Invalid values fail before changing a Node.
Effects follow the owning Node's Cocos lifecycle and restore the unshaken position when they settle or the component is disabled/destroyed.
