Game Development Reference
In-Depth Information
The preceding code will move enemies at the same speed as the background is moved,
and will move the enemy to a somewhat random position in front of the screen once
it goes off screen. This way we will always use only a certain amount of enemies and
won't create any new ones. Re-using things is a good practice, since it saves us memory
and processor time. Next, we need to add some constants that handle the number of
enemies that spawn and power-ups that can spawn.
We will add these to Common.h :
const static NSInteger maximumEnemies = 3;
const static NSInteger maximumPowerups = 1;
Now back in ERGMyScene.m , we will create new enemies and power-ups in the
initWithSize: method:
for (int i = 0; i < maximumEnemies; i++) {
[self addChild:[self spawnEnemy]];
}
for (int i = 0; i < maximumPowerups; i++) {
[self addChild:[self spawnPowerup]];
}
Now it's time to change the appearance of enemies. Create a new particle effects file
for them and name it as enemy.sks . You can configure them the way you like, but I
used the following properties for enemies:
Particles: 500
Lifetime: 0.05
Position and range: zero
Angle: 0 with 360 range
Speed: 400
Acceleration: Zero on both the axes
Scale: 0.1 with 0.1 range and 1 speed
Rotation: At zero and yellow color
And the following properties for power-ups:
Particles: 400
Lifetime: 1
Position range: X at 20 and Y at 0
Angle: 90 with 0 range
 
Search WWH ::




Custom Search