Use a light blue sky gradient as the background.
View code
game.backgroundGradient = { from: "#6ec8ff", to: "#e8f7ff" };
Colors, painted scenes, and backgrounds that scroll to give a game depth.
Try each example, then copy the words under it and paste them to your AI. You can also send your AI the link to an example.
A background sets the mood before anything moves.
Use a light blue sky gradient as the background.
game.backgroundGradient = { from: "#6ec8ff", to: "#e8f7ff" };
A picture made for the game. When its shape differs from the screen, you choose whether it fits inside, fills the screen, or stretches.
Use a painted seaside background, filling the whole screen even if its edges are cut off.
const sea = game.addBackground(new BackgroundLayer("sea"));
sea.fit = "cover";
Layers that scroll at different speeds, far ones slowly and near ones fast, make a flat game feel deep.
Make the background scroll to the left, with the near waves moving four times as fast as the far clouds.
farClouds.x -= 60 * dt;
nearWaves.x -= 60 * 4 * dt;
A level can be wider than the screen. The camera follows the player, and the score stays put in the corner instead of scrolling away with the world.
Make the camera follow the player through a level wider than the screen, with the score fixed in the top corner of the screen.
game.scrollX = player.x - 200;
scoreText.ignoreScroll = true;
The sky over the game can change as it is played.
Rain that splashes, snow that settles on the ground, wind that blows leaves and pushes the player, fog, lightning, fireflies, and nightfall come from an optional ambient module.
Say which weather you want and when it should change. The agent loads the ambient module, which blends one weather into the next and keeps rain out of caves and shelters. Rain, snow, fog, and glowing dots need no pictures; falling leaves, petals, and bubbles are drawn as the game's own images.
See the ambient moduleAdd rain that turns into a thunderstorm when the player reaches the forest, with the wind pushing the player and no rain inside the cave.