Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

How do I handle the situation of an enemy spawn place being visible on a screen in a scrolling shooter? The tutorials I have seen are about setting all the enemies on a whole map only. But it is not appropriate if the map is huge.

share|improve this question
1  
You'll have to elaborate more, how do you want them to be handled? Is being visible not OK? What does "setting all the enemies on a whole map only" mean? What's the specific issue you're facing? –  Byte56 Apr 27 '12 at 17:43
    
It means that I have a big tiled map (which is bigger than an iPhone screen) with enemy spawn locations and I want to generate the enemies when their spawn locations are visible only. Is it clear for you now? –  Gargo Apr 28 '12 at 8:18

1 Answer 1

up vote 2 down vote accepted

If I am interpreting your question correctly, you do not want your enemies to have already spawned because your “world” is so large. As such, you want them to spawn only when the player is approaching the spawn point.

If your scroller moves at a constant pace, then you could spawn your enemies after a specific time interval. If your scroller does not move at a constant pace, or if it is multi-directional, then you need something to trigger spawning. Checking the distance between the player and the spawn point would work, assuming you don’t have thousands of spawn points. Or if they cross over a “trigger” object in your world, that could be used to spawn your enemies.

There are many approaches you could take. Depending on the number of enemies and the size of your world, you could easily have your enemies already spawned, but inactive. Generally, just having them in existence is not nearly as CPU intensive as updating them within your game loop, but there are exceptions.

So, you can have them already spawned, but they don’t come to life until certain conditions are met, such as the distance between the player and the enemy, or if the player touches or shoots the enemy, etc.

Since you tagged your question with Cocos2d, take a look at this tutorial:

http://www.packtpub.com/article/cocos2d-iphone-surfing-through-scenes

It will pretty much guide you through the entire process of creating a game from start to finish. The game is simple, but you will learn the basics and some handy techniques.

Also look here for many helpful tutorials.

http://www.raywenderlich.com/tutorials

I hope this helps.

share|improve this answer
    
I think you have understood me. You game me a useful idea: to create all the enemies and let them to check the y distance to some visible point of the screen. But I still don't think that it is appropriate for me to load and handle all the enemies in iPhone memory. I want to create something look like "Gun Nac" (or Zanac) with a huge amount and a huge variety of enemies. –  Gargo Apr 28 '12 at 8:32
    
I have seen your links. These articles are not very useful: 1)They look like as if their authors don't know cocos2d at all (for example, they can use CCMoveBy and CCRepeatForever or write their own function to move the ship and use it as CCAction but they use almost manual updating via timer which is available even without opengl). The using of cocos2d is limited with scene creation and sprite loading there. 2)they use too simply examples when enemies are too easy and fully randomly generated (it doesn't depends on the current map position). –  Gargo Apr 28 '12 at 9:29
    
The trigger can be used to activate an enemy that is already loaded, or load and then activate the enemy. Whatever you want to do. I'm surprised that you did not find any of those tutorials particular useful. There are so many, and they cover a lot of material. Why you believe the authors "don't know cocos2d at all" is surprising. To each their own. –  Pluvius Apr 30 '12 at 17:41
    
For eample, [self.mySprite setPosition:ccp(self.mySprite.position.x,self.mySprite.position.y - self.movementSpeed)]; in update function. WTF? Why do they create a discrete motion if he can use CCAction (or similar) to create a smooth moving. –  Gargo May 2 '12 at 6:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.