Skip to content
Back to skills

Scroll With Camera

ASecurity

Move a single global offset so a world larger than the screen scrolls, then keep it inside the world's edges.

  • 17 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 7, 2026
development

Security analysis

A100/100

Scanned November 24, 2026

npx -y skills add blit386/blit386 --skill scroll-with-camera --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Scroll With Camera?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Scroll With Camera
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/blit386-scroll-with-camera/badge)](https://www.skillsdirectory.com/skills/blit386-scroll-with-camera)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: scroll-with-camera
description:
  Scroll a world larger than the screen using the global camera offset and keep it clamped inside the world bounds. Use
  for side-scrollers, top-down maps, or any level bigger than the screen that should follow the player.
---

# Scroll with a camera

Move a single global offset so a world larger than the screen scrolls, then keep it inside the world's edges.

## How to do it

Set the camera in `update()`, draw the world in `render()`, then reset the camera before the HUD:

```js
async init() {
    // ...
    this.worldSize = new Vector2i(1280, 960);
    return true;
}

update() {
    // ...move the player...
    // Center the camera on the player, then clamp so it never shows past the world edge.
    const wanted = new Vector2i(
        this.player.x - Math.floor(BT.displaySize.x / 2),
        this.player.y - Math.floor(BT.displaySize.y / 2),
    );
    BT.cameraSet(BT.cameraClamp(wanted, this.worldSize));
}

render() {
    BT.clear(COLOR_BACKGROUND);
    // Draw in WORLD coordinates - the camera offset is applied for you.
    BT.drawRectFill(new Rect2i(this.player.x, this.player.y, 16, 16), COLOR_PLAYER);

    BT.cameraReset(); // back to screen space: the HUD below does not scroll
    BT.systemPrint(new Vector2i(6, 6), COLOR_TEXT, `Score ${this.score}`);
}
```

The reset only lasts until the next `update()` sets the camera again, so the world keeps scrolling on the next frame.

## Key calls

- `BT.cameraSet(offset)` (method) - set the global scroll offset (`Vector2i`).
- `BT.camera` (getter) - the current offset.
- `BT.cameraReset()` (method) - back to `(0, 0)`.
- `BT.cameraClamp(camera, worldSize, viewSize?)` (method) - return an offset kept inside the world bounds.

## Notes

- Draw everything in world coordinates; the camera shifts the whole frame.
- For a fixed HUD or mini-map, draw it after `BT.cameraReset()` so it does not scroll.
- Offsets are whole numbers.
- For a camera that glides instead of stepping on a fast screen, see the `smooth-the-motion` skill.

See `docs/input.md` for moving the player.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.