Joethemonkey101
Joethemonkey101

Reputation: 149

Universal 'move' Method

I made a 'move' method for my enemy to move. The thing is that I have multiple different types of enemies, so I want them all to move relatively the same way. The only difference is the CCSpriteBatchNode, meaning the graphics are different. Is there a way to have the same move method, except modified a bit for each enemy type? Or is the only solution to copy and paste the method to each class and modify it there?

Upvotes: 0

Views: 95

Answers (2)

Dan Ray
Dan Ray

Reputation: 21893

All your enemies should be a subclass of an "Enemy" base class. Implement the "move" function once, in the parent class, and then all the enemy subclasses will move the same way.

Upvotes: 1

M'vy
M'vy

Reputation: 5774

If you are using an object oriented approach you can do this with inheritance and virtual functions. I guess objective C support this kind of programming.

Upvotes: 0

Related Questions