This module keeps track of active game objects.
This allows you to iterate over all objects, or subsets.
-
Add this url to
Assets->game.project->Dependencieshttps://github.com/brpollock/defold-tracking/archive/master.zip
-
Then select
Project->Fetch Libraries
You need to require this module in the object's
script and call track() to start tracking, and untrack()
to stop.
trk = require('tracking.tracking')
local function init(self)
trk.track()
-- ...
end
local function final(self)
trk.untrack()
-- ...
end
The function get() returns a table of tracked IDs as keys.
local objs = trk.get()
for id, _ in pairs(objs) do
local pos = go.get_position(id)
print(pos)
endAll objects are tracked in one table, but you can also
track 'classes' (groups) of objects separately, by specifying
a 'class' when calling track().
trk.track("enemies")And you can specify a class when calling get().
local enemies = trk.get("enemies")
local friends = trk.get("friends")But note that all objects are still tracked as one list.
local everyone = trk.get()