Skip to content
selimanac edited this page Dec 19, 2024 · 11 revisions

See: Category & Mask Bits

For objects that are static or infrequently moving, it is recommended to use daabbcc.insert_aabb() instead of daabbcc.insert_gameobject() to avoid unnecessary calculations.

daabbcc.insert_aabb(group_id,x,y,width,height,[category_bit])

Insert AABB into the group.

Parameters

  • group_id (uint8) - Group ID
  • x (float) - x position of AABB.
  • y (float) - y position of AABB.
  • width (uint32) - Width of AABB.
  • height (uint32) - Height of AABB.
  • category_bit (uint64)[optional] - Single category bit which aabb belongs to. Default is all

Returns

  • aabb_id (int32) - New aabb ID

Example

-- Example mask
local collision_bits = {
	PLAYER      = 1, 
	ENEMY       = 2, 
	ITEM        = 4
}
local x = 0
local y = 0
local width = 50
local height = 50
local group_id = aabb.new_group()

local aabb_id = daabbcc.insert_aabb(group_id, x, y, width, height, collision_bits.PLAYER)

-- OR --

self.pos = go.get_position(".")
self.size = go.get("#sprite", "size")
self.group_id = aabb.new_group()

self.aabb_id = aabb.insert_aabb(self.group_id, self.pos.x , self.pos.y, self.size.x, self.size.y, collision_bits.PLAYER)

daabbcc.insert_gameobject(group_id,go_url,width,height,[category_bit],[get_world_position])

Insert Gameobject and the associated AABB into a group. Most suitable for constantly moving gameobjects. If your gameobject is static then use daabbcc.insert_aabb() instead.

Parameters

  • group_id (uint8) - Group ID
  • go_url (msg.URL) - URL of Gameobject.
  • width (uint32) - Width of AABB.
  • height (uint32) - Height of AABB.
  • category_bit (uint64)[optional] - Single category bit which aabb belongs to. Default is all
  • get_world_position (bool)[optional] - Get world position of gameobject. Default is false

Returns

  • aabb_id (int32) - New aabb ID

Example

-- Example mask
local collision_bits = {
	PLAYER      = 1, 
	ENEMY       = 2, 
	ITEM        = 4,
}
local go_url = msg.url("/go")
local width = 50
local height = 50
local group_id = aabb.new_group()

local aabb_id = daabbcc.insert_gameobject(group_id, go_url, width, height, collision_bits.ENEMY, false)

daabbcc.update_aabb(group_id,aabb_id,x, y, width,height)

Updates the AABB position and size when you change its position or/and size. Gameobject AABB positions will be overwritten by internal update when it is set.

Parameters

  • group_id (uint8) - Group ID
  • aabb_id (int32) - AABB ID.
  • x (float) - X position of AABB.
  • y (float) - Y position of AABB.
  • width (uint32) - Width of AABB.
  • height (uint32) - Height of AABB.

Example

local x = 0
local y = 0
local width = 50
local height = 50
local group_id = aabb.new_group()
local aabb_id = aabb.insert_aabb(group_id, x, y, width, height)

local new_x = 10
local new_y = 10
local new_width = 60
local new_height = 60

daabbcc.update(group_id, aabb_id, new_x, new_y, new_width, new_height)

daabbcc.update_gameobject_size(group_id, aabb_id, width, height)

Updates the AABB size related to the Gameobject.

Parameters

  • group_id (uint8) - Group ID
  • aabb_id (int32) - AABB ID.
  • width (uint32) - Width of AABB.
  • height (uint32) - Height of AABB.

Example

local go_url = msg.url("/go")
local width = 50
local height = 50
local group_id = aabb.new_group()
local aabb_id = aabb.insert_gameobject(group_id, go_url, width, height)
	
local new_width = 60
local new_height = 60

daabbcc.update_gameobject_size(group_id, aabb_id, new_width, new_height)

daabbcc.remove(group_id, aabb_id)

Removes the AABB and Gameobject from group.

Parameters

  • group_id (uint8) - Group ID
  • aabb_id (int32) - AABB ID.

Example

local go_url = msg.url("/go")
local width = 50
local height = 50
local group_id = aabb.new_group()
local aabb_id = aabb.insert_gameobject(group_id, go_url, width, height)

daabbcc.remove(group_id, aabb_id)