- boom
- components
- events
- gameobject
- info
- level
- math
- scene
- timer
File: boom/boom.lua
Boom is a game framework built on top of Defold. It is heavily inspired by the Kaboom.js game framework.
Start a boom game. Call this from your own game script
PARAMS
game
[function
] - Game loop function
File: boom/components/anchor.lua
Anchor component. Use this component to offset any rendered component such as a SpriteComp from the center of the game object.
local bullet = add({
sprite("bullet"),
anchor("left")
})
Anchor point for render.
PARAMS
anchor
[string
] - Anchor (center, topleft, left, topright, right, bottomright, bottom, bottomleft)
RETURNS
component
[AnchorComp
] - The anchor component.
Anchor point.
File: boom/components/area.lua
Area component. Use this component to define a collider area and bounds for a game object. The area can be either a rectangle or a circle. The size can either be set manually or based on the size of a renderable component, such as a sprite.
local player = add({
sprite("player"),
area("auto")
})
Create a collider area and enabled collision detection. This will create an area component which is used to describe an area which can collide with other area components.
PARAMS
options
[table
] - Component options (shape, width, height, radius)
RETURNS
area
[AreaComp
] - The area component
Url of the collision object used by the area
Get all collisions currently happening for this component.
RETURNS
collisions
[table
] - List of collisions
Check collision between this component and another object.
PARAMS
GameObject
[other_object
] - The game object to check collisions with.
RETURNS
bool
[collision
] - Return true if colliding with the other objectdata
[table
] - Collision data
Register event listener when this component is colliding.
PARAMS
tag
[string
] - Optional tag which colliding object must have, nil for all collisionscb
[function
] - Function to call when collision is detected
Register event listener when this component is clicked.
PARAMS
cb
[function
] - Function to call when clicked
Check if a point is within the area of this component.
PARAMS
point
- The point to check
RETURNS
result
[bool
] - Will return true if point is within area
File: boom/components/body.lua
Physical body that responds to gravity. Requires AreaComp and PosComp components on the game object. This also makes the object solid.
PARAMS
options
[table
] - Component options (jump_force, is_static)
RETURNS
component
[BodyComp
] - The body component
If the body is in contact with ground.
If the body is falling (velocity is pointing down).
If the body is jumping (velocity is pointing up).
The upward velocity applied to the body when jumping.
If the body is static and not affected by gravity.
Add upward force.
PARAMS
force
[number
] - The upward force to apply
File: boom/components/color.lua
Component to control the color of the game object.
local bullet = add({
sprite("red-bullet"),
color(1, 0, 0)
})
Create a color component
PARAMS
...
- R,g,b components or color
RETURNS
component
[ColorComp
] - The color component
Current color.
File: boom/components/double_jump.lua
Enables double jump. Requires "body" component.
PARAMS
options
[table
] - Component options (num_jumps)
RETURNS
component
[DoubleJumpComp
] - The double jump component
Maximum number of jumps.
Performs double jump (the initial jump only happens if player is grounded)
PARAMS
force
[number
] - The upward force to apply
File: boom/components/fadein.lua
Fade in game object visual components such as sprites.
add({
text("Hello World"),
fadein(2)
})
Fade object in.
PARAMS
time
[number
] - In seconds
RETURNS
component
[FadeInComp
] - The fade in component.
File: boom/components/fixed.lua
Make object unaffected by camera.
local score = 100
local score_text = add({
text("SCORE: " .. score),
anchor("topleft"),
pos(5, height() - 5)
})
Create a fixed component
RETURNS
component
[FixedComp
] - The component
File: boom/components/health.lua
Handles health related logic.
local enemy = add({
sprite("monster"),
area("auto"),
pos(100, 100),
health(3)
})
enemy.on_collide("bullet", function(collision)
enemy.hurt(1)
end)
enemy.on_death(function()
destroy(enemy)
end)
Create a health component
PARAMS
hp
[number
] - Initial health (default is 1)
RETURNS
component
[HealthComp
] - The health component
Current hp.
Register an event that runs when heal() is called.
PARAMS
cb
[function
] - Function to call
Register an event that runs when hurt() is called.
PARAMS
cb
[function
] - Function to call
Register an event that runs when health is 0 or less.
PARAMS
cb
[function
] - Function to call
Increase hp. Will trigger on_heal.
PARAMS
n
[number
] - Amount to increase
Decrease hp. Will trigger on_hurt
PARAMS
n
[number
] - Amount to decrease
File: boom/components/lifespan.lua
Destroy the game object after certain amount of time. Use this component when you need a game object to be destroyed after a period of time.
add({
text("Gone in 90 seconds"),
lifespan(90, { fade = true })
})
Create a Lifespan component.
PARAMS
time
[number
] - In secondsoptions
[table
] - (fade)
RETURNS
component
[LifespanComp
] - The created component
File: boom/components/move.lua
Component to move a game object in a direction of travel and at a specific speed.
-- move towards a direction infinitely
local projectile = add({
sprite("bullet"),
pos(player.pos),
move(vec2(0, 1), 1200),
})
Create a move component.
PARAMS
direction
[vec2
] - Direction of movement.speed
[number
] - Speed of movement in pixels per second.
RETURNS
component
[MoveComp
] - The created component.
File: boom/components/offscreen.lua
Control the behavior of a game object when it goes out of view
-- move towards a direction infinitely
local projectile = add({
sprite("bullet"),
pos(player.pos),
move(vec2(0, 1), 1200),
offscreen({ destroy = true })
})
Create an offscreen component.
PARAMS
options
[table
] - (distance, destroy)
RETURNS
component
[OffscreenComp
] - The created component
Register a callback that runs when the object goes out of view
PARAMS
cb
[function
] - Function to call when the object goes out of view
Register a callback that runs when the object enters view
PARAMS
cb
[function
] - Function to call when the object enters view
File: boom/components/opacity.lua
Component to control the opacity of a game object.
Create an opacity component.
PARAMS
opacity
[number
] - The opacity from 0.0 to 1.0
RETURNS
component
[OpacityComp
] - The created component.
The opacity of the component instance.
File: boom/components/pos.lua
Position of a game object.
-- this game object will draw a "bean" sprite at (100, 200)
add({
pos(100, 200),
sprite("bean")
})
Create a position component.
PARAMS
x
[number
] -y
[number
] -
RETURNS
component
[PosComp
] - The created component
Move a number of pixels per second.
PARAMS
x
[number
] -y
[number
] -
File: boom/components/rotate.lua
Rotate a gameobject
Apply rotation to object
PARAMS
angle
[number
] - Angle in degrees
RETURNS
component
[RotateComp
] - The created component.
File: boom/components/scale.lua
Scale a gameobject
Apply a scale to the object
PARAMS
x
-y
-
RETURNS
ScaleComp
- Component The scale component.
Set new scale.
PARAMS
x
[number
] -y
[number
] -
Change scale.
PARAMS
x
[number
] -y
[number
] -
File: boom/components/sprite.lua
Render as a sprite.
local player = add({
sprite("player", { atlas = "playercharacter" })
})
player.play("walk")
Render a sprite.
PARAMS
anim
[string
] - Which animation or image to useoptions
[table
] - Extra options (flip_x, flip_y, width, height)
RETURNS
component
[SpriteComp
] - The created component
The current animation
The width of the sprite
The height of the sprite
If sprite should be flipped horizontally
If the sprite should be flipped vertically
Play an animation
PARAMS
anim
[string
] - The animation to play
Stop the current animation
File: boom/components/stay.lua
Do not destroy the game object on scene change.
Do not get destroyed on scene switch.
RETURNS
component
[StayComp
] - The created component
File: boom/components/text.lua
Render as text
local score = add({
text("Score: 0")
})
score.text = "Score: 1"
Render text.
PARAMS
text
[string
] - The text to showoptions
[table
] - Text options (width, font, align)
RETURNS
component
[TextComp
] - The created component
The text to render
File: boom/components/timer.lua
Run an action once or repeatedly at a set interval
Run certain action after some time.
PARAMS
n
[number
] - Number of seconds to waitfn
[function
] - The function to call
RETURNS
component
[TimerComp
] - The created component
Run a callback function after n seconds
PARAMS
n
[number
] - Secondsfn
[function
] - The function to call
Run a callback function every n seconds
PARAMS
n
[number
] - Secondsfn
[function
] - The function to call
Cancel the timer
File: boom/components/z.lua
Determines the draw order for objects. Object will be drawn on top if z value is bigger.
PARAMS
z
[number
] - Z-value of the object.
RETURNS
component
[ZComp
] - The created component
The z value
File: boom/events/collision.lua
Register an event that runs when two game objects collide.
PARAMS
tag1
[string
] - Tag which the first game object must havetag2
[string
] - Optional tag which the second game object must havefn
[function
] - Will receive (collision, cancel) as args
RETURNS
cancel
[function
] - Cancel event function
File: boom/events/key.lua
Register callback that runs when a certain key is pressed.
PARAMS
key_id
[string
] - The key that must be pressed or nil for any keycb
[function
] - The callback
RETURNS
fn
[function
] - Cancel callback
Register callback that runs when a certain key is released.
PARAMS
key_id
[string
] - The key that must be released or nil for any keycb
[function
] - The callback
RETURNS
fn
[function
] - Cancel callback
Check if a certain key is down.
PARAMS
key_id
[string
] - The key that must be down, or nil for any key
RETURNS
down
[bool
] - True if down
File: boom/events/mouse.lua
Set mouse click listener.
PARAMS
tag
[string
] - Optional click on object with tag filtercb
[function
] - Callback when mouse button is clicked
RETURNS
fn
[function
] - Cancel listener function
Register callback that runs when left mouse button is pressed.
PARAMS
button
[string
] - Optional button ("left", "right", "middle", default is "left")cb
[function
] - The callback
RETURNS
fn
[function
] - Cancel callback
Register callback that runs when left mouse button is released.
PARAMS
button
[string
] - Optional button ("left", "right", "middle", default is "left")cb
[function
] - The callback
RETURNS
fn
[function
] - Cancel callback
Register callback that runs when the mouse is moved.
PARAMS
cb
[function
] - The callback
RETURNS
fn
[function
] - Cancel callback
Get mouse position (screen coordinates).
RETURNS
pos
[vec2
] - Mouse position
File: boom/events/update.lua
Run a function every frame. Register an event that runs every frame, optionally for all game objects with certain tag
PARAMS
tag
[string
] - Run event for all objects matching tag (optional)fn
[function
] - The event function to call. Will receive object and cancel function.
File: boom/gameobject/gameobject.lua
Add a game object with a set of components.
PARAMS
comps
[table
] - The components for the game object
RETURNS
object
[GameObject
] - The created game object
Add a game object as a child of this game object.
PARAMS
comps
[table
] - The game object components
RETURNS
GameObject
[table
] - The game object
Destroy this game object
Check if there is a certain tag on this game object.
PARAMS
tag
[string
] - The tag to check
RETURNS
result
[bool
] - Returns true if the tag exists on the game object
Add a component to this game object.
PARAMS
comp
[table
] - The component to use
Remove a component from this game object.
PARAMS
tag
[string
] - The component tag to remove
Get state for a specific component on this game object.
PARAMS
tag
[string
] - The component to get state for
RETURNS
state
[table
] - The component state
Destroy a game object and all of its components.
PARAMS
object
[GameObject
] - The object to destroy
Destroy all objects with a certain tag.
PARAMS
tag
[string
] - The tag to destroy or nil to destroy all objects
Get game object with specific id.
PARAMS
id
[string
] -
RETURNS
string
[id
] - The object or nil if it doesn't exist
Get all game objects.
RETURNS
table
[objects
] - All game objects
Get all game objects with the specified tag.
PARAMS
tag
[string
] - The tag to get objects for, nil to get all objects
RETURNS
objects
[table
] - List of objects
Run callback on every object with a certain tag.
PARAMS
tag
[string
] - The tag that must exist on the objectcb
[function
] - The callback to run
File: boom/info/camera.lua
Get or set camera position.
PARAMS
x
- Or vec2y
-
RETURNS
position
- Camera position
Get or set camera rotation.
PARAMS
angle
- The angle to set or nil to get current rotation
RETURNS
rotation
- The camera rotation in degrees
Get or set the camera zoom.
PARAMS
zoom
- The zoom to set or nil to get the current zoom.
RETURNS
The
- Camera zoom
Transform a point from world position to screen position.
PARAMS
p
- Point
RETURNS
position
- Screen position
Transform a point from screen position to world position.
PARAMS
p
- Point
RETURNS
position
- World position
File: boom/info/gravity.lua
Get gravity
RETURNS
gravity
[number
] - The gravity in pixels per seconds
Set gravity
PARAMS
gravity
[number
] - Gravity in pixels per seconds
File: boom/info/screen.lua
Get screen width
RETURNS
Width
- Of screen
Get screen height
RETURNS
Height
- Of screen
Get screen center position
RETURNS
Center
- Of screen (vec2)
File: boom/info/time.lua
Get the delta time
RETURNS
dt
- Delta time
Get time since start
RETURNS
time
- Time since start in seconds
File: boom/level/level.lua
Construct a level based on symbols.
PARAMS
map
[table
] - List of strings presenting horizontal rows of tilesoptions
[table
] - Level options (tile_width, tile_height, pos, tiles)
RETURNS
level
[GameObject
] - Game object with tiles as children
File: boom/math/random.lua
Get a random number. If called with no arguments the function returns a number between 0 and 1. If called with a single argument 'a' a number between 0 and 'a' is returned. If called with two arguments 'a' and 'b' a number between 'a' and 'b' is returned.
PARAMS
a
[number
] -b
[number
] -
RETURNS
number
[number
] - Random number
Same as rand() but floored.
PARAMS
a
[number
] -b
[number
] -
RETURNS
number
[number
] - Random integer number
File: boom/math/rgb.lua
Color in RGBA format.
The red color component
The green color component
The blue color component
The alpha (tranparency) of the color
Clone the Color.
RETURNS
color
[Color
] - The cloned color.
Lighten the Color.
PARAMS
n
[number
] - Amount to lighten color by
RETURNS
color
[Color
] - The lighter color.
Darkens the Color.
PARAMS
n
[number
] - Amount to darken color by
RETURNS
color
[Color
] - The darker color.
Invert the Color.
RETURNS
color
[Color
] - The inverted color.
Red color.
Green color.
Blue color.
Black color.
White color.
Create Color from a hex string.
PARAMS
hex
[string
] - Hex string in RGB, RGBA, RRGGBB or RRGGBBAA format (with optional initial #).
RETURNS
color
[Color
] - The created color.
Create a Color.
PARAMS
r
[number
] - Red component (0.0 to 1.0)g
[number
] - Green component (0.0 to 1.0)b
[number
] - Blue component (0.0 to 1.0)a
[number
] - Alpha component (0.0 to 1.0)
RETURNS
color
[Color
] - The created color.
File: boom/math/tween.lua
Tween a value from one to another. The transition will happen over a certain duration using a specific easing function.
PARAMS
duration
[number
] - Time in seconds to go from start to end valueeasing
[string
] - Which easing algorithm to useset_value
[function
] - Function to call when the value has changed
RETURNS
controller
[TweenController
] - A tween controller object.
Register an event when finished
PARAMS
fn
[function
] - The function to call when the tween has finished
Finish tween now.
Cancel tween.
File: boom/math/vec2.lua
Vector type for a 2D point (backed by Defold vmath.vector3())
Create a Vec2
PARAMS
x
[number
] - Horizontal positiony
[number
] - Vertical position
RETURNS
v2
[Vec2
] - The created vec2
Get distance between another vector.
RETURNS
distance
[number
] - The distance.
UP vector
DOWN vector
LEFT vector
RIGHT vector
File: boom/scene/scene.lua
Create a scene.
PARAMS
id
[string
] - Unique id of the scenefn
[function
] - The scene code
Show a scene.
PARAMS
id
[string
] - Id of the scene to show...
- Additional arguments to pass to the scene function
File: boom/timer/timer.lua
Run a callback after a certain nummber of seconds.
PARAMS
seconds
[number
] - Number of seconds to waitcb
[function
] - Function to call
RETURNS
cancel
[function
] - Call to cancel the timer
Run a callback repeatedly with a certain interval
PARAMS
seconds
[number
] - Interval between callscb
[function
] - Function to call
RETURNS
cancel
[function
] - Call to cancel the timer