Skip to main content

Scene

The Scene global provides fields and functions relating to the Simulo scene.

Fields

FieldDescriptionNoteDefaultType
Scene.titleThe name of the scene"Untitled Scene"string
Scene.background_colorThe color shown behind the scene0x34213dnumber
Scene.runtime_versionThe version of the Simulo RuntimeRead-onlystring
Scene.box2d_versionThe version of Box2D used in the Simulo runtimeRead-only3.0.0string

Functions

note

Make sure to use Scene:function() and not Scene.function(), or you'll get an error


Scene:add_box(...)

Adds a new box to the scene. Takes a table as parameter, returns a SimuloObject.

Example

Scene:add_box({
position = vec2(0, 0),
size = vec2(1, 1),
color = 0xe5d3b9,
is_static = false,
});

Table Fields

Table FieldDescriptionNote
position Vec2Where to spawn the box
size Vec2Size of the box in meters
color numberColor of the box, like 0xe5d3b9
is_static booleanShould the box be "glued to the background"?
name stringWhat should the name of the box be? Defaults to "Box"Optional

Scene:add_circle(...)

Adds a new circle to the scene. Takes a table as parameter, returns a SimuloObject.

Example

Scene:add_circle({
position = vec2(0, 0),
radius = 1,
color = 0xe5d3b9,
is_static = false,
});

Table Fields

Table FieldDescriptionNote
position Vec2Where to spawn the circle
radius numberRadius of the circle in meters
color numberColor of the circle, like 0xe5d3b9
is_static booleanShould the circle be "glued to the background"?
name stringWhat should the name of the circle be? Defaults to "Circle"Optional

Scene:add_component(...)

Adds a new component to the scene. Takes a table as parameter, returns a Component Hash.

For a detailed explanation, check out the Components section of the API Docs.

Example

Scene:add_component({
name = "My Component",
version = "0.1.0",
id = "@john_doe/test/my_component",

-- Lua/Luau code
code = [[
function on_start()
print("Hello, worlds!");
end;
]],
});

Table Fields

Table FieldDescriptionNote
name stringWhere to spawn the circle
version stringComponent metadata version, defaults to "0.1.0"Optional
id stringUnique ID for your component, should be something like "@yourname/projectname/componentname"
code stringLuau script for the component

Scene:add_simulon(...)

Adds a simulon to the scene, Simulo's mascot. Returns nothing.

This function may be removed by public release, where users will instead be able to spawn simulons just like any other saved object.

Example

Scene:add_simulon({
position = vec2(0, 0),
density = 1,
color = 0xff0000,
});

Table Fields

Table FieldDescriptionNote
position Vec2Where to spawn the simulon
density numberDensity for the simulon
color numberSimulon color, defaults to 0xa9bc67Optional

Scene:get_object_by_guid(...)

Returns the SimuloObject of the given guid, or nil if it doesn't exist.

Example

local object = Scene:get_object_by_guid(20);

Scene:get_all_objects()

Returns a table which is a list of SimuloObjects.

Example

local objects = Scene:get_all_objects();

-- Destroy all objects in scene
for i=1,#objects do
objs[i]:destroy();
end;

Scene:get_gravity()

Returns a Vec2 of the scene's gravity.

Example

local gravity = Scene:get_gravity();

print(tostring(gravity));

Scene:set_gravity(...)

Sets the scene's gravity to a Vec2. Returns nothing.

Example

Scene:set_gravity(vec2(0, -15));

Scene:overlap_circle(...)

Returns a table which is a list of SimuloObjects that overlap with a circle. Does not actually create any circle shape.

Example

local objects_in_circle = Scene:overlap_circle({
position = vec2(0, 0),
radius = 10,
});

-- Print the GUIDs
for i=1,#objects do
print("Object of GUID " .. tostring(objs[i].guid) .. " was in circle");
end;

Table Fields

Table FieldDescriptionNote
position Vec2Center of the circle
radius numberRadius of the circle

Scene:add_hinge_at_world_point(...)

Adds a hinge at a world point, connecting two SimuloObjects. Returns a SimuloHinge.

Example

local object_a = Scene:get_object_by_guid(1);
local object_b = Scene:get_object_by_guid(2);

local hinge = Scene:add_hinge_at_world_point({
point = vec2(0, 0),
object_a = object_a,
object_b = object_b,
motor_enabled = false,
motor_speed = 1, -- radians per second
max_motor_torque = 10, -- maximum torque for the motor, in newton-meters
});

hinge:destroy();

Table Fields

Table FieldDescriptionNote
point Vec2World point for the hinge
object_a SimuloObjectFirst object for the hinge
object_b SimuloObjectSecond object for the hinge
motor_enabled boolShould the hinge have a motor? Defaults to falseOptional
motor_speed numberRadians per secondOptional
max_motor_torque numberMaximum torque for the motor, in newton-metersOptional

Scene:explode(...)

Applies an impulse in the scene at a given point to all objects in its radius.

note

The explosion impulse does not depend on distance, all objects in the radius will get the same impulse.

Example

Scene:explode({
position = vec2(0, 0),
radius = 10,
impulse = 10.
});

Table Fields

Table FieldDescriptionNote
position Vec2Center of the explosion
radius numberRadius of the explosion
impulse numberImpulse of the explosion