From 54b01b0d945f62c076434077dcb6d7ac5cfffca5 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 16 Jun 2019 10:08:59 +0200 Subject: [PATCH] feat(world): add a creationID variable to keep track of actors ID --- CHANGELOG.md | 2 ++ gamecore/modules/world/baseworld.lua | 3 +++ gamecore/modules/world/world2D.lua | 5 ++++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3da99d1..12319ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **world:** Support batching actor loading +- **world:** Add `Actor.creationID` to keep the order in which actors have been created + ### Changed - **world:** automatize world integration in a scene diff --git a/gamecore/modules/world/baseworld.lua b/gamecore/modules/world/baseworld.lua index a1f0ee1..ded38f0 100644 --- a/gamecore/modules/world/baseworld.lua +++ b/gamecore/modules/world/baseworld.lua @@ -84,6 +84,7 @@ end function BaseWorld:initActors( ) self.actors = {} + self.currentCreationID = 0 end function BaseWorld:newActor(name, x, y) @@ -95,6 +96,8 @@ function BaseWorld:newCollision(name, x, y, w, h) end function BaseWorld:registerActor(actor) + actor.creationID = self.currentCreationID + self.currentCreationID = self.currentCreationID + 1 table.insert(self.actors, actor) end diff --git a/gamecore/modules/world/world2D.lua b/gamecore/modules/world/world2D.lua index d63b074..7375c46 100644 --- a/gamecore/modules/world/world2D.lua +++ b/gamecore/modules/world/world2D.lua @@ -38,10 +38,13 @@ end -- Wrappers around Bump2D functions function World2D:initActors() - self.actors = Bump.newWorld(50) + self.currentCreationID = 0 + self.actors = Bump.newWorld(50) end function World2D:registerActor(actor) + actor.creationID = self.currentCreationID + self.currentCreationID = self.currentCreationID + 1 return self.actors:add(actor, actor.x, actor.y, actor.w, actor.h) end