SNKRX/engine/game/parent.lua

20 lines
723 B
Lua
Raw Normal View History

2021-02-18 05:11:25 +01:00
-- This useful to add to objects that need to have some kind of relationship with their parents.
-- Call the appropriate function in the object's update function every frame.
-- The game object must have a .parent attribute defined and pointing to another game object.
Parent = Object:extend()
-- Follows the parent's transform exclusively.
-- This means that if the parent dies the entity also dies.
-- The .parent attribute is niled on death.
function Parent:follow_parent_exclusively()
if self.parent and self.parent.dead then
self.parent = nil
self.dead = true
return
end
self.x, self.y = self.parent.x, self.parent.y
self.r = self.parent.r
self.sx, self.sy = self.parent.sx, self.parent.sy
end