-
-
Notifications
You must be signed in to change notification settings - Fork 9
Home
You can use the A* extension in your own project by adding this project as a Defold library dependency.
Open your game.project
file, select Project
and add a Dependencies
field:
https://github.com/selimanac/defold-astar/archive/master.zip <- TODO 3.0
or you can add stable versions from releases.
Flappy Bird Clone: https://github.com/selimanac/DAABBCC-Flappybird-Example
Breakout: https://github.com/selimanac/DAABBCC-Breakout-Example
Defold Forum: https://forum.defold.com/t/daabbcc-dynamic-aabb-tree-native-extension-with-branch-and-bound-algorithm
New empty group for AABBs.
RETURN
-
group_id
(int) - New group ID.
EXAMPLE
local group_id = aabb.new_group()
Insert AABB into the group.
PARAMETERS
-
group_id
(int) - Group ID. -
x
(number) - X position of AABB. -
y
(number) - Y position of AABB. -
width
(int) - Width of AABB. -
height
(int) - Height of AABB.
RETURN
-
aabb_id
(int) - New AABB ID.
EXAMPLE
local x = 0
local y = 0
local width = 50
local height = 50
local group_id = aabb.new_group()
local aabb_id = aabb.insert(group_id, x, y, width, height)
-- OR --
self.pos = go.get_position(".")
self.size = go.get("#sprite", "size")
self.group_id = aabb.new_group()
self.aabb_id = aabb.insert(self.group_id, self.pos.x , self.pos.y, self.size.x, self.size.y)
Insert Gameobject and the associated AABB into a group.
Most suitable for moving gameobjects. If your gameobject is static then use aabb.insert
instead.
PARAMETERS
-
group_id
(int) - Group ID. -
url
(msg.url) - URL of Gameobject. -
width
(int) - Width of AABB. -
height
(int) - Height of AABB.
RETURN
-
aabb_id
(int) - New 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)
Updates the AABB position and size when you change its position or size.
Gameobject AABB positions will be overwritten.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - AABB ID. -
x
(number) - X position of AABB. -
y
(number) - Y position of AABB. -
width
(int) - Width of AABB. -
height
(int) - 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(group_id, x, y, width, height)
local new_x = 10
local new_y = 10
local new_w = 60
local new_h = 60
aabb.update(group_id, aabb_id, new_x, new_y, new_w, new_h)
Updates the AABB size related to the Gameobject.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - AABB ID. -
width
(int) - Width of AABB. -
height
(int) - 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_w = 60
local new_h = 60
aabb.update_gameobject(group_id, aabb_id, new_w, new_h)
Query the possible overlaps using AABB ID.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - AABB ID.
RETURN
-
result
(table) - Table of possible overlapping AABBs. -
count
(int) - Count ofresult
table.
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 result, count = aabb.query_id(group_id, aabb_id)
if result then
for i = 1, count do
print(result[i])
end
end
Query the possible overlaps without AABB ID.
PARAMETERS
-
group_id
(int) - Group ID. -
x
(number) - X position. -
y
(number) - Y position. -
width
(int) - Width. -
height
(int) - Height.
RETURN
-
result
(table) - Table of possible overlapping AABBs. -
count
(int) - Count ofresult
table.
EXAMPLE
local x = 0
local y = 0
local width = 50
local height = 50
local group_id = aabb.new_group()
local result, count = aabb.query(group_id, x, y, width, height)
if result then
for i = 1, count do
print(result[i])
end
end
Query the possible overlaps using AABB ID.
Returns result table with ids and distance, ordered by closest first.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - AABB ID.
RETURN
-
result
(table) - Table of possible overlapping AABBs. Result table containsaabb_id
anddistance
. -
count
(int) - Count ofresult
table.
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 result, count = aabb.query_id_sort(group_id, aabb_id)
if result then
for i = 1, count do
print(result[i])
end
end
Query the possible overlaps without AABB ID.
Returns result table with ids and distance, ordered by closest first.
PARAMETERS
-
group_id
(int) - Group ID. -
x
(number) - X position. -
y
(number) - Y position. -
width
(int) - Width. -
height
(int) - Height.
RETURN
-
result
(table) - Table of possible overlapping AABBs. Result table containsaabb_id
anddistance
. -
count
(int) - Count ofresult
table.
EXAMPLE
local x = 0
local y = 0
local width = 50
local height = 50
local group_id = aabb.new_group()
local result, count = aabb.query_sort(group_id, x, y, width, height)
if result then
for i = 1, count do
print(result[i])
end
end
Query the possible overlaps using RAYCAST.
PARAMETERS
-
group_id
(int) - Group ID. -
start_x
(number) - Ray start position X. -
start_y
(number) - Ray start position Y. -
end_x
(number) - Ray end position X. -
end_y
(number) - Ray end position Y.
RETURN
-
result
(table) - Table of possible overlapping AABBs. -
count
(int) - Count ofresult
table.
EXAMPLE
local group_id = aabb.new_group()
local ray_start = vmath.vector3(0, 0, 0)
local ray_end = vmath.vector3(365, 370, 0)
local result, count = aabb.raycast(group_id, ray_start.x, ray_start.y, ray_end.x, ray_end.y)
if result then
for i = 1, count do
print(result[i])
end
end
Query the possible overlaps using RAYCAST.
Returns result table with ids and distance, ordered by closest first.
PARAMETERS
-
group_id
(int) - Group ID. -
start_x
(number) - Ray start position X. -
start_y
(number) - Ray start position Y. -
end_x
(number) - Ray end position X. -
end_y
(number) - Ray end position Y.
RETURN
-
result
(table) - Table of possible overlapping AABBs. Result table containsaabb_id
anddistance
. -
count
(int) - Count ofresult
table.
EXAMPLE
local group_id = aabb.new_group()
local ray_start = vmath.vector3(0, 0, 0)
local ray_end = vmath.vector3(365, 370, 0)
local result, count = aabb.raycast_sort(group_id, ray_start.x, ray_start.y, ray_end.x, ray_end.y)
if result then
for i = 1, count do
print(result[i])
end
end
Removes the group and all associated AABBs and Gameobjects.
PARAMETERS
-
group_id
(int) - Group ID.
EXAMPLE
local group_id = aabb.new_group()
aabb.remove_group(group_id)
Removes the AABB and Gameobject from group.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - 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)
aabb.remove(group_id, aabb_id)
Removes gameobject and the associated AABB.
You don't need to call aabb.remove
again for removing AABB.
PARAMETERS
-
group_id
(int) - Group ID. -
aabb_id
(int) - 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)
aabb.remove_gameobject(group_id, aabb_id)
Stop/resume Gameobject position update iteration.
It is true
by default, but does not iterate when when there are no Gameobjects registered.
PARAMETERS
-
state
(boolean) - True/False
EXAMPLE
aabb.run(true)
Clear everything (AABBs,groups, gameobjects) and reset to initial state.
EXAMPLE
aabb.clear()
It is possible to set a independent update frequency for gameobject loop. Default value is set from game.project file(display.frequency).
PARAMETERS
-
update_frequency
(int) - Update Frequency.
EXAMPLE
aabb.update_frequency(5)
If you find my Defold Extensions useful for your projects, please consider supporting it.
I'd love to hear about your projects! Please share your released projects that use my native extensions. It would be very motivating for me.