{"id":13524447,"url":"https://github.com/idbrii/love-parallax","last_synced_at":"2025-09-25T02:31:44.753Z","repository":{"id":67130622,"uuid":"348961593","full_name":"idbrii/love-parallax","owner":"idbrii","description":"A utility library for LÖVE that adds parallax scrolling to your camera.","archived":false,"fork":false,"pushed_at":"2022-01-11T08:35:16.000Z","size":2263,"stargazers_count":14,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-11-02T08:32:28.121Z","etag":null,"topics":["love2d","parallax","parallax-scrolling"],"latest_commit_sha":null,"homepage":"https://idbrii.github.io/love-parallax/demo/","language":"Lua","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/idbrii.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,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-03-18T06:12:59.000Z","updated_at":"2024-08-14T18:25:49.000Z","dependencies_parsed_at":"2023-03-17T21:45:30.130Z","dependency_job_id":null,"html_url":"https://github.com/idbrii/love-parallax","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idbrii%2Flove-parallax","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idbrii%2Flove-parallax/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idbrii%2Flove-parallax/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/idbrii%2Flove-parallax/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/idbrii","download_url":"https://codeload.github.com/idbrii/love-parallax/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234147879,"owners_count":18786934,"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":["love2d","parallax","parallax-scrolling"],"created_at":"2024-08-01T06:01:10.170Z","updated_at":"2025-09-25T02:31:39.448Z","avatar_url":"https://github.com/idbrii.png","language":"Lua","funding_links":[],"categories":["Camera"],"sub_categories":[],"readme":"[![Tested on love2d 11.3+\n](https://img.shields.io/badge/L%F6ve-11.3%2B-pink.svg)](https://love2d.org/) [![Lint status\n](https://github.com/idbrii/love-parallax/actions/workflows/luacheck.yml/badge.svg?branch=main)\n](https://github.com/idbrii/love-parallax/actions?query=branch%3Amain)\n\n# parallax\n\nparallax is a camera utility library for [LÖVE](https://love2d.org) that\nadds parallax scrolling when used with a camera library.\n\nparallax is not itself a camera system!\n\nparallax was developed using LÖVE 11.3, but may work on earlier versions.\n\n## Quick Start\n\nThis is a very minimal example of using parallax, but [there's a more involved\ndemo](#demo).\n\n![parallax-quick-start](https://user-images.githubusercontent.com/43559/111591121-3f28bf80-8784-11eb-9ffa-f8fb74d2f838.gif)\n\n```lua\nlocal gamera = require('gamera') -- https://github.com/kikito/gamera\nlocal parallax = require('parallax')\n\nlocal layers = {}\nlocal player = {}\nlocal camera\n\nfunction love.load()\n    camera = gamera.new(0,0,2000,700)\n    layers.near = parallax.new(camera, 1.5)\n    layers.far = parallax.new(camera, 0.25)\n    player.x = camera.ww / 2\n    player.base_y = camera.wh * 2 / 3\n    player.jump = 100\n    player.y = 0\n    player.width = 10\n    player.half = player.width / 2\n    player.speed = 500\nend\n\nfunction love.update(dt)\n    -- move the player around so we can see the layers move\n    player.x = player.x + player.speed * dt\n    if player.x \u003c= 0 or camera.ww \u003c player.x then\n        player.speed = player.speed * -1\n    end\n    player.y = player.base_y + math.cos(player.x / 100) * player.jump\n    camera:setPosition(player.x, player.y)\nend\n\nlocal function draw_all(l,t,w,h)\n    local rect_w = 50\n    local offset = camera.ww * 2\n\n    layers.far:draw(function()\n        -- Draw something distant from the camera here.\n        love.graphics.setColor(0,0.2,0.7,0.3)\n        for x=-offset,offset,rect_w do\n            local rh = love.math.noise(x/w) * 1200\n            love.graphics.rectangle('fill', x, -900, rect_w, rh)\n        end\n    end)\n\n    -- Draw the game here\n    love.graphics.setColor(1,1,1,1)\n    love.graphics.rectangle('fill', player.x - player.half, player.y - player.half, player.width, player.width)\n    love.graphics.setColor(0,0.7,0.7,0.3)\n    love.graphics.rectangle('fill', -camera.ww, player.base_y + player.jump, camera.ww * 2, camera.wh)\n\n    layers.near:draw(function()\n        -- Draw something near the camera here.\n        for x=-offset,offset,rect_w do\n            local rh = love.math.noise(x/w) * 150\n            love.graphics.rectangle('fill', x, camera.wh - 50, rect_w, -rh)\n        end\n    end)\nend\n\nfunction love.draw()\n    love.graphics.clear()\n    camera:draw(draw_all)\nend\n```\n\n## Demo\n\nThere's a [demo branch](https://github.com/idbrii/love-parallax/tree/demo) that\ndemonstrates a more complex program using parallax. It uses\n[gamera](https://github.com/kikito/gamera) for its camera and demonstrates\nmultiple ways the camera can be transformed while maintaining correct parallax\norientation.\n\n\n## Functions\n\n### parallax.new(camera, scale, speed)\n\nCreates a new parallax object.\n\n- `camera`: _table_. A camera object containing x,y (camera position), w2,h2 (half camera width and height), angle (camera rotation), and scale (camera scaling factor). gamera provides all of these.\n- `scale`: _number_. The scale for this layer. Larger numbers look closer and smaller look more distant.\n- `speed`: _number_. Optional. A speed scale for this layer's movement. A number closer to zero makes it move slower (and look more distant) without changing its size.\n\n### layer:draw(f)\n\nDraw input function on the parallax layer. Should be called inside love.draw.\n\n- `f`: _function_ A function that does drawing operations.\n\n### layer:setOffset(x,y)\n\nGive the parallax layer an offset from the camera's position. If you have a\nbackground layer, you may want to move it down to see more of the ceiling area.\n\n- `x, y`: _numbers_. This offset adjusts the position of the layer relative to the camera.\n\n### layer:translateOffset(dx,dy)\n\nSet incremental changes to the parallax layer's offset. Allows you to fine tune\nhow the layer is displayed.\n\n- `dx, dy`: _numbers_. Increment the offset by these values.\n\n\n### layer:draw_tiled_xy(x, y, image)\n\nDraw an image (or Canvas or Video) tiled using a minimal number of draws. Uses\ninverseTransformPoint so transformations from your camera should ensure only\nvisible tiles are drawn.\n\n- `x, y`: _numbers_. Tune the positioning of the image.\n- `image`: _Drawable_. A drawable (Image, Canvas) that provides getDimensions to draw tiled.\n\n- returns: _number_. The number of times the image was drawn.\n\n\n### layer:draw_tiled_single_axis(x, y, image, axis)\n\nDraw an image (or Canvas or Video) tiled using a minimal number of draws and\nonly along a single axis. See also draw_tiled_xy.\n\n- `x, y`: _numbers_. Tune the positioning of the image.\n- `image`: _Drawable_. A drawable (Image, Canvas) that provides getDimensions to draw tiled.\n- `axis`: _string_. Either `x` to tile horizontally or `y` to tile vertically.\n\n- returns: _number_. The number of times the image was drawn.\n\n\n## Credits\n\n* kikito for [gamera](https://github.com/kikito/gamera) which I built this library to work with.\n* davisdude for [Brady](https://github.com/davisdude/brady) which was instrumental to figuring out how to make parallax work.\n\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidbrii%2Flove-parallax","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fidbrii%2Flove-parallax","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fidbrii%2Flove-parallax/lists"}