So, I've decided to try and implement a 2d side scroller, similar to many in the 8 bit days. An action-RPG probably.
I've decided to use objective-chipmunk for the foundation, which has been really cool so far. Gravity is great, got a TMX map level working with the physics engine to walk around on. I've started looking at adding an enemy, and have run into the problem of wanting to use cocos2d animations to animate my enemies while still using the physics engine. These seem to be somewhat incompatible.
For my first enemy I've started to implement a bat that flies at the player. I'd like this to work something like the green bats in super mario world, or maybe the bats in castlevania. However, with the physics engine they couldn't move through the walls and floors or even through the player, making handling them getting from point A to point B a fairly hefty problem. Additionally trying to animate the wings using joints and the physics engine is kind of a problem. My understanding is that I need to reflect my sprites based on the physics, not move the physics based on sprite animations in order for the engine to work properly.
As a solution I'm thinking about doing the following:
- Create a chipmunk space for the player and the world (and possibly boss fights). This would handle player movement, physics and possibly basic animation.
- Create a separate space for the enemies and/or NPCs. This would allow for gravity to work on enemies as needed. Not all enemies would use this, only ones effected by gravity.
This would solve the problem of the bats and other enemies (maybe ghosts or somesuch) being able to pass through walls, since they would be sprite-based only. Additionally enemies could pass through the player similar to the old platformer games. However! This would also require not using physics for most collision detection, instead using sprite-based collision, and I'd have to define the level physics for two separate spaces.
Alternate options I've thought about are having only one space and having gravity-based enemies simply working differently (they collide with the player and can cause problems there, which would alter gameplay but could be ok) and still have sprite-only based enemies that I have to manage differently. And then there's the physics-only option that doesn't have things that move through walls. I could be wrong but pretty sure you can't have chipmunk objects pass through each other within the same space.
As I'm typing this that last seems like a better way to go, if I can live with the gameplay changes it will cause. Will have to consider that.
I'd love to have feedback on if either of these are a viable option or alternate approaches if anyone has suggestions or experience here. There's plenty of waste here in both, and I'm not sure what the best solution is, or even if I'm looking at this the right way. (I'm new at writing platformers of any kind)