Creating and destroying objects
Create an object
The Create an object action puts a new instance into the running game. You choose the object, the position and the layer.
| Conditions | Actions |
|---|---|
Keyboard: Key just pressed Space |
Create an object Shot at Player.X(), Player.Y() |
Position fields accept expressions. Player.X() is the player's X position.
Tip: objects that will be created by events do not need to be in the layout. They only need to exist in the Object types list.
Newly created objects are already picked
Right after Create an object, the new instance is picked for the event's following actions. That is why you can give it speed straight away:
| Conditions | Actions |
|---|---|
Keyboard: Key just pressed Space |
1. Create an object Shot at Player.X(), Player.Y() 2. Shot Add a force (angle) 0°, speed 600 |
Creating several with different values
To create several objects in a row with different random values, use a Repeat event and create one per repetition. If you create them all in one pass, the following actions apply to the whole group.
Appearing over time
Combine it with a timer. See Timers.
Destroy an object
The object's Delete action removes the instances picked by the event's conditions.
| Conditions | Actions |
|---|---|
Shot Collision with Enemy |
Shot Delete · Enemy Delete |
Destroy when leaving the screen
No events needed: add the Destroy outside behavior to the object. It deletes the instance when it leaves the screen. That stops thousands of shots piling up offscreen and slowing the game down.
| Conditions | Actions |
|---|---|
Enemy Y position > 800 |
Enemy Delete |
Careful
A Delete action on Coin removes every picked coin. If the event has no condition about Coin, that means every coin in the game.