Jakub Matuška - Bachelor's thesis at Masaryk university of Brno. Online scene editor for Box2D with behavior programming.
First things first, here’s a link to the newest deployed version of the editor: https://jkbmat.github.io/bakalarska-praca-dist/.
And here’s some examples of Scenária in action:
Controls: WASD and arrow keys
Here’s how the editor looks once it’s freshly started:
The main sections are:
If no joints or entities are selected, the contextual sidebar shows information about the simulation world.
Here you can set the gravity vector and camera style.
Camera can be either:
To add a new entity to the simulation, simply choose the desired tool and create the entity in the work space using drag & drop. It will be assigned default attributes and a random color.
Each entity is assigned a layer and a collision group. Layers determine the order in which entities are drawn. Collision groups determine which entities should interact with which other entities.
The Collision groups window, accessible form the toolbar, is a place to define collision group interaction.
Collision groups 2 and 3 will now no longer interact
Aside from layer and collision group number, an entity has the following attributes:
Joints bind two entities together and change how they behave. To create a joint, first click on the joint’s button in the toolbar. A dialog will appear in the contextual sidebar, where the connected entities need to be chosen.
After creating the joint, the following attributes can be changed:
Each type of joint can also have additional attributes:
The real strength of Scenária lies in editing Entities’ behaviors. The behavior editor can be accessed by clicking on Set behavior button in the contextual sidebar when an entity is selected.
The behavior system is strongly typed using the following types:
A behavior comprises of two parts:
An entity can have any number of behaviors.
The full list of implemented commands is as follows:
Name | Type | Arguments | Description |
---|---|---|---|
AND | boolean |
|
Evaluates to true if both operands are true, false otherwise |
OR | boolean |
|
Evaluates to true if at least one of the operands is true, false otherwise |
NOT | boolean |
|
Reverses the value of the operand |
true | boolean | Evaluates to true | |
false | boolean | Evaluates to false | |
text | string |
|
Evaluates to a string |
number | number |
|
Evaluates to a number |
randomNumber | number |
|
Evaluates to a random integer in range \ |
+ | number |
|
Evaluates to the sum of its operands |
* | number |
|
Evaluates to the product of its operands |
/ | number |
|
Evaluates to the quotient of its operands |
- | number |
|
Evaluates to the difference of its operands |
> | boolean |
|
Evaluates to true if Operand A is greater than Operand B |
< | boolean |
|
Evaluates to true if Operand A is lesser than Operand B |
= | boolean |
|
Evaluates to true if Operand A is equal to Operand B |
getX | number |
|
Evaluates to x-axis position of the first entity in argument |
getY | number |
|
Evaluates to y-axis position of the first entity in argument |
velocityX | number |
|
Evaluates to x-axis velocity of the first entity in argument |
velocityX | number |
|
Evaluates to y-axis velocity of the first entity in argument |
getGravityX | number | Evaluates to x-axis strength of the world’s gravity | |
getGravityY | number | Evaluates to y-axis strength of the world’s gravity | |
isTouching | boolean |
|
Evaluates to true if any of the entities from Entity filter A are touching any of the entities from Entity filter B |
countEntities | number |
|
Evaluates to the number of entities in Entity filter |
isButtonDown | boolean |
|
Evaluates to true if the specified button is currently pressed |
isButtonUp | boolean |
|
Evaluates to true if the specified button has been released |
You can use keycode.info to find keycodes of buttons.
All entity filters are of type entityfilter. All entity filters except thisEntity
, allEntities
and filterById
take an entityfiler as the first argument, which they then filter further.
Name | Arguments | Description |
---|---|---|
thisEntity | Contains the entity owning the behavior | |
allEntities | Contains all entities in the scene | |
filterById |
|
Contains an entity with the specified ID |
filterByGroup |
|
Contains all entities from Filter that belong to the specified collision group |
filterByLayer |
|
Contains all entities from Filter that belong to the specified layer |
filterByContactWith |
|
Contains all entities from Filter that are touching any of the entities in Entities |
Actions are executed when their behavior’s condition is fulfilled. All actions are of type action.
Name | Arguments | Description |
---|---|---|
setColor |
|
Sets the color to CSS color Color for all Entities |
remove |
|
Removes all Entities |
setGravity |
|
Sets the world’s gravity |
setPosition |
|
Sets the position for all Entities |
setAngularVelocity |
|
Sets the angular velocity for all Entities |
setLinearVelocity |
|
Sets the linear velocity for all Entities |
applyTorque |
|
Applies angular force to all Entities |
applyLinearForce |
|
Applies a linear force to all entities |
applyAngularImpulse |
|
Applies an angular impulse to all entities |
applyLinearImpulse |
|
Applies a linear impulse to all entities |