feat(world): add a creationID variable to keep track of actors ID

This commit is contained in:
Kazhnuz 2019-06-16 10:08:59 +02:00
parent e9f5731a34
commit 54b01b0d94
3 changed files with 9 additions and 1 deletions

View file

@ -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

View file

@ -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

View file

@ -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