add on_update event
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
function on_despawn()
|
||||
print("despawn")
|
||||
end
|
||||
|
||||
inair = true
|
||||
function on_grounded()
|
||||
entity.transform:set_rot(mat4.rotate({0, 1, 0}, math.random()*360))
|
||||
print(stdcomp)
|
||||
entity:despawn()
|
||||
inair = false
|
||||
end
|
||||
|
||||
function on_update()
|
||||
if inair then
|
||||
entity.transform:set_rot(mat4.rotate(entity.transform:get_rot(), {0, 1, 0}, math.random()*32))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,6 +40,21 @@ return {
|
||||
return entity
|
||||
end,
|
||||
remove_Entity = function(eid)
|
||||
entities[eid] = nil;
|
||||
local entity = entities[eid]
|
||||
if entity then
|
||||
entity.env = nil
|
||||
entities[eid] = nil;
|
||||
end
|
||||
end,
|
||||
update = function()
|
||||
for id,entity in pairs(entities) do
|
||||
local callback = entity.env.on_update
|
||||
if callback then
|
||||
local result, err = pcall(callback)
|
||||
if err then
|
||||
print(err)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user