User Tools

Site Tools


Shooting Bullets with a Spawner

This tutorial will show you how to set up a spawner to shoot bullets that can be turned on and off from code. Normally if you attach a spawner to an object, you can only turn it off using orxObject_Enable. But that will make the parent object invisible as well. We use a child object in the case.


You can use the following assets in this tutorial.


In this config, we create a CannonObject. We give it an empty child object called: CannonSwitchingObject. The spawner CannonSpawner is attached to CannonSwitchingObject.

CannonSwitchingObject is the one we will turn on or off to stop the spawner from shooting bullets.

Graphic   = CannonGraphic
Position  = (100, 100, 0)
Scale     = 5
ChildList = CannonSwitchingObject
Texture = spawner-gun.png
Spawner = CannonSpawner
Object          = BulletObject
WaveSize        = 1
WaveDelay       = 0.2
ActiveObject    = 10
Position        = (10, -1, 0)

Next, the bullet object to be fired by the CannonSpawner.

Graphic  = BulletGraphic
Speed    = (300, -15, 0) ~ (300, 15, 0)
LifeTime = 2.0
Texture = spawner-bullet.png


Then in the code, use the cannonObject to get the switchObject by calling orxObject_GetChild on the cannonObject.

Finally, use orxObject_Enable(switchObject, orxFALSE) to stop the spawner shooting bullets, or use orxTRUE to switch it back on.

orxOBJECT *cannonObject;
orxOBJECT *switchObject;
cannonObject = orxObject_CreateFromConfig("CannonObject");
switchObject = (orxOBJECT*)orxObject_GetChild(cannonObject );
orxObject_Enable(switchObject, orxFALSE); //turn off the firing
orxObject_Enable(switchObject, orxFALSE); //turn on the firing

en/tutorials/spawners/spawning_bullets.txt · Last modified: 2018/02/14 00:46 (6 years ago) (external edit)