开发者

objective-c spawn many monsters

开发者 https://www.devze.com 2023-04-05 15:58 出处:网络
I made a little iPhone game but now I wanted to make multiple monsters to spawn. So I have one UIImageView called enemy that spawns at beginning of the game. But I want it to spawn many more monsters

I made a little iPhone game but now I wanted to make multiple monsters to spawn. So I have one UIImageView called enemy that spawns at beginning of the game. But I want it to spawn many more monsters until开发者_如何学Python I say it needs to stop spawning them. I know how to get random locations. I don't want to add like 20 other enemy's and 20 image views and give them all the same function i jus twang to declare one image view called enemy but that image spawns many times.

Any help? Thanks!


Each enemy will likely need its own coordinates, position, hitpoints, spellpoints, etc. So the obvious solution would be to have something like a MonsterTracker class that has an array of Monster objects that you expand to the number of instances you need.


Create a monster factory using the factory pattern. Here's an obj-c example.

0

精彩评论

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

关注公众号