andengine Tower Defence game - Enemy<-Weapon interaction

寵の児 提交于 2019-12-13 02:39:25

问题


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.

  1. 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

  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!