开发者

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 CCSprit开发者_StackOverfloweBatchNode, 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?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜