The following topics will be reviewed:
Game Tab
The game tab is where we define the attributes for our game.
For example: having gravity in the game, the width and height of the world and so on.
These settings can be changed prior to running the game and cannot be changed in the code.
Settings
Name | Description |
Background image | The background image of the game can be changed to either an existing background or an uploaded one. |
World width | Sets the world’s width. The visible part of the world is 600 by 400. |
World height | Sets the world’s height. The visible part of the world is 600 by 400. |
Camera target | Defines which sprite to follow. When the game runs, the camera will move following the sprite. When the world size is 600 by 400, setting this option is meaningless because the entire world can be seen. |
Gravity | Defines the level of gravity in the game. Zero means that there is no gravity and the sprites do not fall down. The gravity also affects how high the sprite jumps or how fast it falls. |
Physics | Defines the physics system of the game. Use Arcade when you need simple physics like in a platformer game. P2 physics allows complex physics in the game. P2 physics can be used for games such as moon lander. Note: some blocks are available only for arcade physics and some only for P2 physics. |
Tip
When the world’s width and height are different from the default values (600 pixels and 400 pixels respectively), the camera target should be set as well. Otherwise, when the sprite moves out of the visible part of the world, it will be out of camera’s sight.
Properties
The table below lists all properties that can be used in the code. Property blocks can be found in the Game and Sounds section.
Name | Description |
Get Game Time | Returns the time elapsed in milliseconds. |
Get Game Time
Returns the time elapsed in milliseconds (thousandths of a second) since the game has been open (not since the game was run). When the game starts, this value will not be zero, so if you want to measure a time period, you need to get a starting value and compare it to the current value.
Example
In this example, the game time is saved at the start of the game. It is then compared to the current time. When the difference is greater than 3000 (or 3 seconds), the sprite will be destroyed.
Blocks
The table below lists all blocks that can be used in the code. The blocks can be used with both physics (arcade and P2). These blocks can be found in the Game and Sounds section.
Block Name | Description |
Resets the game. | |
Pauses the game. | |
Resumes the game. | |
Changes the background. |
Reset Game
Resets the game to its original configuration.
Example
When the timer ends, the game will be reset back to the original configuration.
Pause Game
Pauses the game.
Example
When the sprite is clicked, the game will pause, all sprites will not be moved, timer widgets will stop counting.
Unpause Game
Resumes the game.
Example
When the space bar is pressed, the game will resume, timer widgets will continue counting from the place they were paused.
Set Background
Updates the game background to a new value. When using this block, only CodeMonkey backgrounds can be chosen. You cannot change to a user uploaded background during the game.
Arguments
Name | Type | Description |
New Background | string | The name of the new background enclosed in quotes. |
Example
When the timer ends, the game background will be changed to the Jungle Night background.
Sounds Tab
Sounds are objects in the game. Sound objects can be played by calling the Play Sound block of the sound object. There are various sounds available. The sound can be played before adding it to the game by clicking on the play button.
Blocks
Block Name | Description |
Plays the sound |
Play
Plays the sound.
Examples
Plays a sound named mySound when the game runs.
Tilemaps
Tilemap consists of tiles that can be added to the game.
When using arcade physics, the tiles are used as the ground of the game, meaning sprites can move and jump on them. If gravity is applied to the sprite, then when the game runs, the sprite will fall and land on a tile.
When using P2 physics, the block On Collide With Tilemap can be used to define what to do in case the sprite collides with any of the tiles in the game.
Actions
Action Name | Description |
Add | Add tiles |
Erase | Erase tiles |
There are two icons located on the top right corner of the game screen.
To add tiles, click on the paint brush icon. The available patterns of the tiles are opened on the right-side of the screen. Choose one pattern and click on the screen to add the tiles. Once done, click on the arrow icon (otherwise, each click on the screen will add another tile).
To delete tiles, click on the eraser icon. Go over the tiles that needs to be erased. Once done, click on the arrow icon (otherwise, each click on the screen will erase another tile).
General Blocks
These blocks can be used in the sprites’ and in widgets’ codes.
Blocks
Block Name | Description |
Random from | Returns a number between the minimum number and the maximum number. |
Random from
Returns a random number in between the range of the minimum and maximum numbers provided. Each call to this block will return a different number.
Arguments
Name | Type | Description |
min | number | The minimum number that can be returned. |
max | number | The maximum number that can be returned. |
Returns
Number - a random number between min and max.
Example
In this example, each time the space bar is pressed, a random number will be generated between 10 and 20 and then stored in the ranNumber variable.
Relevant Articles:










