There is additional logic around setting `targetX`/`targetY` to different targets depending on what's going on in the game, and some tweaks to make the camera smoother at very fast or very slow speeds, but that is the basic idea.
Let us know if that was helpful or if you have any other questions.
So 60 times a second, the `tick()` function is called, inside there, it calculates where the camera will be for the next frame, then calls `redraw()` which draws the screen... inside `redraw()`, the camera position is taken into account when drawing the tiles and objects to the screen, offseting things accordingly --
You can view the source code by visiting https://pulp.biz/over-the-moon/ and right clicking the screen and select "View Page Source" for all the gritty details.
← Return to game
Comments
Log in with itch.io to leave a comment.
nice game btw
i also make games with just js also(but without the sprites hehe)
i had confusion on what to make on the 12th edition of the GBJAM and your game just simplified evrything fr me
quick question: as someone who also makes gameswithout ag game engine, how did you implement a camera system to your game?
Hey! Thank you for the kind words about our game.
The core camera system is just a basic lerp:
```
let cameraX = 0;
let cameraY = 0;
// move camera towards user
let targetX = userX - 75;
let targetY = userOnGround ? userY - 95 : userY - 87;
let cameraLag = 0.11;
if (explosion.length > 0) {
// ...set targetX/Y to center of the explosion...
}
cameraX -= (cameraX - targetX) * cameraLag;
cameraY -= (cameraY - targetY) * cameraLag;
```
There is additional logic around setting `targetX`/`targetY` to different targets depending on what's going on in the game, and some tweaks to make the camera smoother at very fast or very slow speeds, but that is the basic idea.
Let us know if that was helpful or if you have any other questions.
Thanks a lot! But can you explain the function that updates the camera position and it's rendering.
(Is this AI generated?)
So 60 times a second, the `tick()` function is called, inside there, it calculates where the camera will be for the next frame, then calls `redraw()` which draws the screen... inside `redraw()`, the camera position is taken into account when drawing the tiles and objects to the screen, offseting things accordingly --
You can view the source code by visiting https://pulp.biz/over-the-moon/ and right clicking the screen and select "View Page Source" for all the gritty details.
Neither our replies or code are AI generated. :)
Let us know if you have any other questions.
HOW
How?
excellent work , faultless gameplay , controls and design !
Thank you for your kind words! We're happy you had fun with it.