This method will check to see if a character will run into the game boundaries on movement.


object: object - The object you are checking for.

axis: string - The axis that the object is moving on (x or y).

distance: number - The distance the object is moving on that axis.


{ validMove, fallbackPos } - Tells you if the move is valid, and if not, will provide a fallback position for your object.


This method can be used once you have bounds set for your game and have created at least one character with movement. It should be used to stop characters from moving through the game boundaries.


Example 1

//File code/server/rooms/room.js
onMessage(client, data) {
	const  player = g.getACharacter('players', client.sessionId);
	const actions = {
		moveUp: () => {
			let newMove = g.checkBounds(player, 'y', -speed);
			if (newMove.validMove) {
				player.y -= speed;
			} else {
				player.y = newMove.fallbackPos;
	g.handleActions(actions, data);


Need Help?

Proofread your code, check with your team and classmates, and if you’re still stuck!

Click Here for Help