问题
What is the most correct from the performance point of view - algorithm of interaction between Enemy and Weapon(bullet maybe more correct here) ?
Should every sprite every single bullet check for collisions via "collidesWith" method with iteration on full enemies list ? Or bullet should be aware about nearest enemies and check only them ?
How it could be implemented with TMXMaps ? Maybe I need to dynamically set some kind of information into the TMXMap Tile properties and operate with it ?
What best practices exists for this kind of game ? Is IShape.collidesWith a right choice for Bullet->Enemy interaction ?
回答1:
The best way to approach this is to use Physics Box2D extension. It will handle the collisions for you. Use Fixed Step Physics Engine to increase performance.
You can add your own property to TMX maps - to each object, group etc. I recommend creating a property on objects that are enemies, because I believe they will be in your TMX map. In your code attach a physics engine body to each object with that property. Look at this example: http://www.andengine.org/forums/tutorials/collision-objects-from-tmx-map-t3907.html
When you fire a bullet, attach a body to it as well. Make it a sensor, so it won't bounce of other objects (unless you want it to). Let the Box2D handle the collisions and you handle the aftermath! Example: http://www.andengine.org/forums/gles2/collision-events-t7140.html#p31300
Go through the AndEngine examples, most of what you want, is already there: https://github.com/nicolasgramlich/AndEngineExamples/tree/GLES2/src/org/andengine/examples
来源:https://stackoverflow.com/questions/16598466/andengine-tower-defence-game-enemy-weapon-interaction