124,678

Views

Beginner

Level

50

Comments

Crash Course 2: Invaders - Part 11

by Hectate (Updated on 2015-05-02)


Part 11: Destroying Bullets

If we didn't do something to remove Bullets from the game correctly, it might eventually affect performance (assuming the player shoots as much as we expect them to). Lets set something up to destroy our Bullets at a couple of key times. Switch to your Bullet actor type's Event tab.

Step 78: Add an Actor of Type Collision Event (click + Add Event button on the left, then select the Event, as shown).

Step 79: Set the Actor Type to Enemy Ship, then drag over a Kill [Self] block from the Palette (under Actor -> Properties).

Now each Bullet Actor will be destroyed when it collides with an Enemy Ship.

Step 80: Next, to ensure our Bullets are also destroyed when they leave the screen, we need to add an Actor Event, when a Specific Actor Enters or Leaves the Screen, as shown:

Step 81: Change the dropdowns on the Event block that appears from enters to exits, and from scene to screen, then drag over a Kill [Self] block (Actor -> Properties in the Palette).

If you were to test your game now, you would probably notice that the bullets don't get destroyed when they collide with the enemies. The reason for this is that the collision group for the bullets is not set to collide with the enemies.

Step 82: Select the Bullet actor type's Properties tab, and make sure that the Group is set to Bullets. Then click "Edit Groups". The Collision Group section of Game Settings will open up. Make sure that the "Bullets" group is highlighted to the right and then click the "Enemies" group so it turns green (as in the image below).

http://static.stencyl.com/help/images/bullets_collision_group.png

Save your game and test it; now the bullets should be disappearing if they collide with the enemies. Next, it’s time to set up what actually happens when Bullets collide with the Enemy Ships, instead of just removing the bullets from the game.

Click here to go to Part 12.

Disclaimer: Use comments to provide feedback and point out issues with the article (typo, wrong info, etc.). If you're seeking help for your game, please ask a question on the forums. Thanks!

50 Comments

altsun
What is the different between scene and screen?
0 3 weeks, 6 days ago
Akanaro
@BOSS1sCOOL - Make sure you select "Specific Actor" when you create the event and not something like "Actor of Type". It works fine for me on 3.4.
0 3 months, 2 weeks ago
BOSS1sCOOL
I have the latest version of Stencyl, which is 3.4, and I can't find the ''self'' button. I think this Crash Course Game is outdated. I'm so MAD!!!
1 3 months, 3 weeks ago
ArkhamKnight9103
It just won't work I checked the Collision groups and everything. Do you need to change it to self? How do you do that?
1 6 months ago
tkeo games
When I spawn in the "always updating" block it instead imports the "WHEN updating and my ship goes off the screen
0 10 months, 3 weeks ago
Cloudy Games
What can replace Hit? I've tried absolutely everything, checking my collision checking my physics checking my properties, I'm pretty sure it's the coding, can someone please help?
1 1 year, 1 month ago
Flashy231
ignore the last comment i was in a scene event palette instead of the bullet actor event palette.
0 2 years, 3 months ago
Flashy231
How can i change the variable to "self"? I only get "Last created actor", "choose actor" and "Choose atribute" in the options available.
3 2 years, 3 months ago
gadget593
In the new Stencyl, on both of these events, the very first variable defaults to Actor Type. You need to change this to Self.
0 2 years, 3 months ago
ABOODXGAMER
to fix problem
don't forget to folllow this steps on event of bullets not of ship !!!!

1 2 years, 3 months ago

Sign In to Comment