Your first game! Part 2: Shooting Stuff

Posted on: March 10, 2015 at 1:01 am,

a2

Making a bullet!

Next up is to create our bullet. We need a new sprite and a new object. Create a new sprite called “spr_bullet“. Now you can design this to your taste but I chose to make a simple 4×4 white square. Just make sure that the origin is properly centered on your bullet!

http://puu.sh/gtNjb/1906fd2a9f.png

Then create a new object called obj_bullet. Assign it to have spr_bullet as a sprite. Feel familiar? This is exactly what we did in part one to create the player spaceship!

For now we only need to create one piece of logic for the bullet itself, we’re going to make it so that we don’t end up with an infinite number of bullets on screen by destroying them when they leave the play area. So first off go ahead and add the “Outside Room” event. After that, in the “Main 1” tab in the actions area, find the “Destroy Instance” action:

http://puu.sh/gtNyc/bd9fb0724b.png

and add it to the event. Make sure “applies to self” is ticked on the dialogue window that pops up and click ok.

destroy

This works as you might expect. When the object is outside the room, gamemaker destroys it! If you want to know how to do this in code, you can accomplish exactly the same thing using “Execute Code” and the line “instance_destroy();” This function will destroy the instance (specific object in a room) which calls it. This function does not have any arguments that need passing along to it, so you can simply open and close the brackets at the end of the command without putting anything in them.

However as destroying the instance is literally all we want to do in this case, we can save our fingers a few presses and just use this handy action as it does exactly the same thing!

Pages: 1 2 3