It looks like you're new here. If you want to get involved, click one of these buttons!
...
void orxFASTCALL StandAlone::Update(const orxCLOCK_INFO* clockInfo, void* context)
{
for(orxOBJECT *pstObj = orxOBJECT(orxStructure_GetFirst(orxSTRUCTURE_ID_OBJECT)); pstObj != orxNULL; pstObj = orxOBJECT(orxStructure_GetNext(pstObj)))
{
std::string ObjectName = orxObject_GetName(pstObj);
if((ObjectName.compare("EnemySpawner") == 0))
{
orxSPAWNER* pstSpawner = orxOBJECT_GET_STRUCTURE(pstObj, SPAWNER);
if((totalSpawned == 3) {
orxSpawner_SetWaveDelay(pstSpawner, 0.5);}
}
}
}
Comments
Are you sure that your spawner description is like you mentionned here ?
Just by looking your code it seems it will be working (spawner shouldn't be stopped), or I didn't see the mistake.
But, I don't understand why you set the WaveDelay to 0.5 because it's alreay the value stored in your config.
If there's only 3 spawned objects, maybe you have a "TotalObject" properties in your spawner description (in the .ini) ?
If you comment you C code, what happens ? Only 3 spawn or more ?
Suggestion : why you didn't keep a reference on your spawner instead of parsing all object to get it ? It will be more efficient.
One remarks more, instead of counting spawned object with your totalSpawned var, I suggest you to use the orxSpawner_GetTotalObjectCounter, I think it's what you want and it's more clean.
Cheers !
Have you got a "ActiveObject = 3" maybe ? This means that the spawner stop spawning until your enemies die.
Because my english sucks a little, I'm not sure to understand. Spawner stop when commenting the orxSpawner_SetWaveDelay(...) or not ?
If yes, try to change your 0.5 to orx2F(0.5). I think it will not solve the problem, but you can try to modify that.
It's really this line; I can't seem to set any of the Spawner properties:
orxSpawner_SetWaveDelay(pstSpawner, 0.5);
I'm doing this simpler code for testing and my spawner doesn't give me any enemies at all:
Spawner in my .ini is still just:
[Spawner]
Object = Enemy
WaveSize = 1
WaveDelay = 1.5
ObjectSpeed = (-80, 0, 0)
CleanOnDelete = True
[EnemySpawner]
Spawner = Spawner
Update() was being called wayyy too fast so it was resetting itself over and over. I'm going to move this to the Spawner event handler instead.
4:00a me isn't the brightest crayon in the box sometimes.
Sure ! It was so easy ... I didn't see that !
There's a much more efficient way of doing what you want. There are many spawner events to which you can listen and act upon the spawner directly.
One of them is orxSPAWNER_EVENT_SPAWN, which is fired everytime an object is spawned. It also contains both the spawned object and the spawner, so no need to crawl through all your objects to update your spawner, it's right there. If you were to create objects "Enemy" from anywhere else, this also has the advantage that you could track them separately, on a per spawner basis.
You can also listen to orxSPAWNER_EVENT_WAVE_STOP, if you wanted to act whenever a wave is over (useful if you decide to spawn more than 1 Enemy per wave).
Lastly, it you set a TotalObject limit on your spawner, no need anymore to track the number of spawned objects manually.
In config, you setup your TotalLimit to 3. In your code you listen to the orxSPAWNER_EVENT_EMPTY, whenever you hit that event, you can then set your spawner limit to something else, update the wave delay and then reset it (orxSpawner_Reset()).
If you're very lazy like me, you can also add the AutoReset property that will call the reset for you, and instead of the empty event, you can listen to orxSPAWNER_EVENT_RESET.
The event approach has the advantage of not crawling through all the objects in your Update and only do the bare minimum for your spawner logic.
Something like:
Note that orxSpawner_SetTotalObjectLimit() with 0 actually removes the limit, so no more empty/auto-reset will happen.