Book Image

Babylon.js Essentials

By : Julien Moreau-Mathis
Book Image

Babylon.js Essentials

By: Julien Moreau-Mathis

Overview of this book

Are you familiar with HTML5? Do you want to build exciting games and Web applications? Then explore the exciting world of game and Web development with one of the best frameworks out there: Babylon.JS. Starting from the beginning, the book introduces the required basics for 3D development and the knowledge you need to use the Babylon.js framework. It focuses on the simplicity provided by Babylon.js and uses a combination of theory and practice. All the chapters are provided with example files ready to run; each example file provides the previously learned features of the framework. Finally, developers will be ready to easily understand new features added to the framework in the future.
Table of Contents (15 chapters)
Babylon.js Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface

Defining actions on objects


The Babylon.js framework comes with a collection of distinct actions. You'll find actions that can play a sound, stop a sound, interpolate a property of an object, set a value of an object property, and so on.

Enable actions on an object

The only entities that can handle ActionManager are the scene and the meshes in the scene. Each Babylon.js mesh has its own action manager reference. To enable actions on a mesh, just create a new reference to the mesh, as follows:

myMesh.actionManager = new BABYLON.ActionManager(scene);

The ActionManager constructor takes only the scene as a parameter.

Let's create your first action in a scene composed of a box and a plane. The action must change the box's position on the y axis from 0 to 6 when the user left-clicks on the box. The only thing to do is to call the .registerAction function on ActionManager of the box, as shown in the following:

myMesh.actionManager = new BABYLON.ActionManager(scene);
myMesh.actionManager.registerAction...