In this example, we'll explore the essential steps for setting up a scene and adding a game object using Beast2D. We'll create our first scene,"MyFirstScene," and integrate it into the default canvas. Then, we'll add a game object, "MyFirstGameObject," and display its position and name.
Finally, we'll implement a global update function to manage the game's runtime environment and clear the screen with a black color, updates the canvas to reflect any changes or interactions, and sets the update cycle to repeat, ensuring smooth execution and continuity of the game loop.
This example serves as a foundation for understanding scene creation, game object integration, and runtime management in Beast2D. You can take a look at the live example of the code running below.
DOWNLOAD EXAMPLE
//### EXAMPLE: BASIC SCENE SETUP ###
//create first scene and add it to the default canvas.
// By default the object is placed at the center of the screen
var myScene=scene("MyFirstScene",canvas)
//now lets add a game object
var myGameObject=myScene.addGameObject("MyFirstGameObject");
//lets get some information on game object like its position and name
myGameObject.getOrientation(true);
// global update function
function update() {
// Clear screen with black color
clear("black");
// Update the canvas object
canvas.update();
// Set the update to repeat
setTimeout(update, canvas.timeout);
}
update();
Live view