{"id":15483515,"url":"https://github.com/hackergrrl/game-camera-2d","last_synced_at":"2025-06-24T15:34:20.101Z","repository":{"id":147533390,"uuid":"46316902","full_name":"hackergrrl/game-camera-2d","owner":"hackergrrl","description":":movie_camera: A simple 2D camera that's suited for games.","archived":false,"fork":false,"pushed_at":"2015-11-17T02:24:48.000Z","size":8,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T18:52:59.575Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hackergrrl.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-17T02:07:28.000Z","updated_at":"2015-11-25T06:00:38.000Z","dependencies_parsed_at":"2023-04-13T03:03:57.683Z","dependency_job_id":null,"html_url":"https://github.com/hackergrrl/game-camera-2d","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hackergrrl/game-camera-2d","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgame-camera-2d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgame-camera-2d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgame-camera-2d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgame-camera-2d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hackergrrl","download_url":"https://codeload.github.com/hackergrrl/game-camera-2d/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hackergrrl%2Fgame-camera-2d/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261703547,"owners_count":23196986,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T05:17:40.833Z","updated_at":"2025-06-24T15:34:20.027Z","avatar_url":"https://github.com/hackergrrl.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# game-camera-2d\n\n\u003e A simple 2D camera suited for games.\n\n\n# Install\n\n```bash\n$ npm install game-camera-2d\n```\n\n\n# Usage\n\n```js\nvar camera = createCamera({\n  left: 0,\n  right: 640,\n  top: 0,\n  bottom: 480\n})\n\ncamera.setTranslation(64, 64)\ncamera.setRotation(Math.PI / 4)\ncamera.setScale(0.5)\n\nvar matrix = camera.getMatrix()\nconsole.dir(matrix)\n```\n\noutputs a 3x3 matrix compatible with\n[gl-mat3](https://www.npmjs.com/package/gl-mat3):\n```\nFloat32Array {\n  '0': 0.0011048543965443969,\n  '1': -0.001473139156587422,\n  '2': 0,\n  '3': -0.0011048543965443969,\n  '4': -0.001473139156587422,\n  '5': 0,\n  '6': 0,\n  '7': 0.18856181204319,\n  '8': 1 }\n```\n\n# API\n\n## var camera = require('game-camera-2d')(options)\n\nCreates a new camera object. The `options` object contains the following\noptional parameters:\n\n- `left` - the coordinate of the left side of the screen.\n- `right` - the coordinate of the right side of the screen.\n- `top` - the coordinate of the top of the screen.\n- `bottom` - the coordinate of the bottom of the screen.\n- `x` - the X coordinate to centre the camera on.\n- `y` - the Y coordinate to centre the camera on.\n- `angle` - the rotation to apply around the screen centre.\n- `scale` - the scaling factor to apply.\n\n\n## Properties\n\n### camera.width, camera.height\n\nWidth and height of the camera viewport, in units.\n\n### camera.x, camera.y\n\nThe camera's current X/Y offset from the origin.\n\n### camera.rotation\n\nThe rotation of the camera viewport, in radians.\n\n### camera.scale\n\nThe scaling factor of the camera.\n\n\n## Methods\n\n### camera.getMatrix([out])\n\nRetrieves the current state of the camera matrix.\n\n`out` is a length 9 array which receives the result of the computation if not\notherwise specified.\n\n**Returns** The resulting camera matrix\n\n### camera.setTranslation(x, y)\n\nSets the X/Y offset from the origin for the camera to be centred on.\n\n### camera.setRotation(angle)\n\nSets the rotation around the translation coordinates, in radians.\n\n### camera.setScale(scale)\n\nSets the scaling factor of the camera at the translation coordinates.\n\n\n## Additional Credit\n\nHeavily inspired by Mikola Lysenko's\n[camera-2d](https://github.com/mikolalysenko/camera-2d) module.\n\nI really liked the idea of a lightweight 2D camera that spits out a 3x3\ntransformation matrix, but wanted an API that made both absolute and relative\noperations easy.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fgame-camera-2d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhackergrrl%2Fgame-camera-2d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhackergrrl%2Fgame-camera-2d/lists"}