如何在 iPhone 版 cocos2d 中无限生成敌人/小行星?
有没有任何例子显示类似小行星的游戏具有无限的敌人/小行星生成?
如何使用 cocos2d 和 box2d 做到这一点?
PS:他们应该来自四面八方......
is there any example that shows a asteroid like game with unlimited enemy/asteroids spawning?
How can I do this with cocos2d and box2d?
PS: They should come from all directions...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的问题太笼统了,以至于你看起来像是在黑暗中爬行。
你想要的是设置敌人的最大数量,然后随机地(可能因最大敌人和当前敌人之间的差异而产生偏差,这样,如果敌人较少,产生新敌人的机会就更高)你产生它们。
您可以使用
-(void)update:(ccTime)dt
方法来完成此操作,该方法会在整个显示的每次重绘时由 cocos2d 生命周期自动调用。您可以通过在CCLayer
子类的 init 方法中调用[self ScheduleUpdate]
来启用此自动调度。Your question is so general that you seem like just crawling into the dark.
What you want is to set a maximum amount of enemies and then randomly (possibly biased by the difference between maximum enemies and current enemies, so that if there are less enemies the chance to spawn a new one is higher) you spawn them.
You can do it in
-(void)update:(ccTime)dt
method which is automatically called by cocos2d life cycle on every repaint of the whole display. You can enable this automatic scheduling by calling[self scheduleUpdate]
in the init method of yourCCLayer
subclass.