miaoda-game-vision-cocos
v0.3.1
Published
Cocos Creator skin for miaoda-game-vision2d-core: fills the visibility polygon / flashlight cone with Graphics, and bridges line-of-sight to Cocos's own PhysicsSystem2D.raycast. The reusable rendering + query layer for stealth vision, fog-of-war and guard
Maintainers
Readme
miaoda-game-vision-cocos
Use this Cocos Creator adapter to draw continuous visibility polygons/cones with Graphics and to bridge simple line-of-sight checks to Cocos PhysicsSystem2D.raycast.
Install and use
pnpm add miaoda-game-vision2d-core miaoda-game-vision-cocosCocos Creator provides the optional cc peer dependency at runtime.
import { VisionLayer } from 'miaoda-game-vision-cocos';
const layer = lightRoot.addComponent(VisionLayer).setup({
fillColor: { r: 255, g: 240, b: 180, a: 90 },
});
layer.obstacles.addBounds({ minX: 0, minY: 0, maxX: 960, maxY: 640 });
layer.obstacles.addRect({ minX: 400, minY: 300, maxX: 460, maxY: 360 });
layer.renderCone(guardPos, facingDeg, 70, 400);
if (layer.inView(guardPos, facingDeg, 70, playerPos, 400)) raiseAlarm();Call renderFrom or renderCone from your game loop; the layer does not auto-tick. Add bounds before rendering to close the ring. physicsLineOfSight is for collider-backed clear/blocked checks only; visibility polygons still use the core obstacle geometry.
