How does the game state interact with a component-based entity?
I've been doing some reworking of my flash framework lately and as I make about one game a month, the idea of re-useable components to quickly prototype concepts seems really appealing to me.
The factor that's holding me 开发者_运维技巧back is how the game state pulls out information from entities themselves.
For example, centering a camera on the player is usually quite easy: camera.x = player.x;
but I'm not sure how you'd do something like that with component based entities.
Any ideas or links to systems where you can easily pull that kind of data?
You can have the components to produce event and the interested parties to register listeners for these events. for Instance you camera can listen to other components's moves. This approach should be simple and robust enough for you needs.
final Camera camera = new Camera() ;
Player player = new Player() ;
player.OnMove += new MovementListener() {
public void onMove(Position newPosition) {
camera.UpdatePositionWith(newPosition)
}
}
Hope it helps.
精彩评论