Now that we have created the image for our bullets, we have to take it into GameSalad and start creating the bullet behaviors. This will involve movement, spawning, and more; so, let's get right into it.
Bullet
and drag in the bullet image (or directly drag the image from the Library to the Actors section to create an actor from that image). Double-click that actor so we can edit it. Under the Graphics roll-out, change the Blending Mode to Additive
. Now, drag in a Move behavior and change the Direction to 90
, and the Speed to 1000
. Shooting
and change the settings to Actor receives event | key | space | is | down. 0.2
seconds. Then, drag in two Spawn Actor behaviors. Change the settings of the first one to:Bullet
self.Rotation
-8
: 5
in back of actor
scene
Bullet
self.Rotation
8
: 5
in back of actor
scene
Muzzle Flash
. Double-click it so we can edit it. Change the Blending Mode to Additive
. Drag in a Timer behavior and change the timer to 0.1
seconds, then drag in a Destroy behavior. Muzzle Flash
, and change the second position to 50
or more, whatever makes it look like it's coming right out of the barrel.Voila! It looks pretty good, right? Now, we have to "program" the bullet collisions with the enemies.
In a few short moments, we were able to make our character shoot bullets in the direction our player faces and even spice it up with some muzzle flashes. A simple Spawn Actor behavior makes it quite easy to create many bullets! Unlike Xcode and programming our games, we don't have to set up an NSMutableArray similar to the following code:
(This code is here purely to show you the contrast between coding our game, and using GameSalad.)
//declare this in the header file NSMutableArray *Array; UIImageView *charShot; BOOL shooting; //code this in the main file for(charShot in Array) { CGPoint newCenter = charShot.center; newCenter.x = newCenter.x + 25; charShot.center = newCenter; } if (Array == nil) { Array = [[NSMutableArray alloc] init]; } UIImage *bulletImage = [UIImage imageNamed: @"image.png"]; charShot = [[UIImageView alloc] initWithImage: bulletImage]; if (shooting == YES) { for(int i=0; i<1; i++) { int x = character.center.x + 25; int y = character.center.y; [self.view addSubview:charShot]; [Array addObject:charShot]; } }
That's how you code it. Now that you look at it, doesn't it make you happy that you are using GameSalad? That didn't even include the collisions, muzzle flashes positions, and autodestruction! I'm not even going to begin to explain how to program that... Ok, now let's get back to work.
3.138.67.27