feat(world): add a creationID variable to keep track of actors ID
This commit is contained in:
parent
e9f5731a34
commit
54b01b0d94
3 changed files with 9 additions and 1 deletions
|
@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
- **world:** Support batching actor loading
|
- **world:** Support batching actor loading
|
||||||
|
|
||||||
|
- **world:** Add `Actor.creationID` to keep the order in which actors have been created
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- **world:** automatize world integration in a scene
|
- **world:** automatize world integration in a scene
|
||||||
|
|
|
@ -84,6 +84,7 @@ end
|
||||||
|
|
||||||
function BaseWorld:initActors( )
|
function BaseWorld:initActors( )
|
||||||
self.actors = {}
|
self.actors = {}
|
||||||
|
self.currentCreationID = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWorld:newActor(name, x, y)
|
function BaseWorld:newActor(name, x, y)
|
||||||
|
@ -95,6 +96,8 @@ function BaseWorld:newCollision(name, x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
function BaseWorld:registerActor(actor)
|
function BaseWorld:registerActor(actor)
|
||||||
|
actor.creationID = self.currentCreationID
|
||||||
|
self.currentCreationID = self.currentCreationID + 1
|
||||||
table.insert(self.actors, actor)
|
table.insert(self.actors, actor)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,10 +38,13 @@ end
|
||||||
-- Wrappers around Bump2D functions
|
-- Wrappers around Bump2D functions
|
||||||
|
|
||||||
function World2D:initActors()
|
function World2D:initActors()
|
||||||
|
self.currentCreationID = 0
|
||||||
self.actors = Bump.newWorld(50)
|
self.actors = Bump.newWorld(50)
|
||||||
end
|
end
|
||||||
|
|
||||||
function World2D:registerActor(actor)
|
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)
|
return self.actors:add(actor, actor.x, actor.y, actor.w, actor.h)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue