Here we're creating a game object with a number of components, each of which give our object some data or behavior.
#Sprite screen wrap code
To initialize these layers, add the code below to the bottom of the main.js file: In this game, we'll use three layers: the background layer ( bg), the object layer ( obj), and UI layer ( ui). The layer an object is on will determine when it gets drawn and which other objects it can collide with. Scenes are further divided into layers, which are populated by game objects (also called sprites). In this tutorial, we'll just use one scene, which will contain the entire game logic. You can use scenes for game levels, menus, cut-scenes and any other screens your game might contain. Setting the scene Ī Kaboom.js game is made up of scenes, which you can think of as different screens, levels or stages. We also use similar code to load sound elements for our game using the loadSound function. Then each line loads a game sprite and gives it a name so that we can refer to it in code later. The first line, loadRoot, specifies which folder to load all the sprites and game elements from, so we don't have to keep typing it in for each sprite. Replace the code in main.js with the code below: To start, we need to initialise and set up Kaboom with the scale we want for the game window. Once you've uploaded the files, you can click on the "Kaboom" icon in the sidebar, and return to the "main" code file. Click the "Files" icon on the sidebar then, upload everything in Sounds folder to the "sounds" section of your repl, and everything in the Sprites folder to the "sprites" section of your repl.
#Sprite screen wrap zip file
Download this ZIP file and extract it on your computer.
Kaboom repls are quite different from other kinds of repls you may have seen before: instead of dealing directly with files in folders, you'll be dealing with scenes, sounds and sprites.īefore we start coding, we need to upload our sprites and sounds. Log into your Replit account and create a new repl. Creating a new project and loading assets We've created a single ZIP file with the sprites and sounds you will need for this tutorial, which you can download here. We will also be using music by Eric Matyas of. We will use these Asteroids sprites and this space background from, and the following sounds from :
Following our previous tutorial on building Snake, in this tutorial we'll implement Asteroids, one of the first major arcade game hits, developed by Atari in 1979.