Removing a state (clearState() ?)

Burkey

29-04-2007 21:58:11

Hi all,

I'm wondering how would you go about removing all states from a body? In my game, for example if a player was on fire when they died, I want them to respawn with no state, ie. no longer ON_FIRE. I've tried _body->clearState(ON_FIRE); but this doesn't seem to work at all. Any ideas would be most helpful.

Thanks in advance.

betajaen

29-04-2007 22:08:07

Hmm, is your state machine handling the On_Fire::clear state?

It should stop the visualisation of the fire, then set itself to on_fire::delete. Then main state machine should destroy it for you.

Burkey

29-04-2007 22:13:12

Thanks for the reply. I'm really not sure, sorry (I'm a n00b at this stuff).

Here is my state machine header file:

#ifndef __myCustomStateMachine_H__
#define __myCustomStateMachine_H__

#include "nxOgre.h"
#include "Ogre.h"

using namespace nxOgre;
using namespace Ogre;

// define the states
enum myStates {FLAMMABLE = 1, ON_FIRE = 2, IS_WET = 3};


// class definition - derived from customStateMachine class
class myCustomStateMachine : public customStateMachine {

public:

// handle the state change
bool simulate(body *_body, state &_state) {


// if state is DESTROY or ACTIVATED then ignore
if (_state.status == DESTROY || _state.status == ACTIVATED)
return false;

// call the appropriate method to handle the new state
switch (_state.type) {

case ON_FIRE:
return set_ON_FIRE(_body, _state);
break;
case IS_WET:
return set_IS_WET(_body, _state);
break;
}

//nothing happened - pass onto next state machine
//if there is one
return false;
}


// handle a new ON_FIRE state
bool set_ON_FIRE (body *_body, state &_state) {

// check that the state has only just been actioned
if (_state.status == STARTED) {

// create a new child node of the top cube
SceneNode* mParticleNode =
_body->mNode->createChildSceneNode(
_body->getName() + "particlefx");

// create the fire – a particle system
ParticleSystem* mParticleSystem = _body->owner->mSceneMgr->createParticleSystem(_body->getName() + "fx", "nx.fx.smoke");

// attach it to the new child node
mParticleNode->attachObject(mParticleSystem);


// set the state status to activated
// avoids calling this again
_state.status = ACTIVATED;

// all done
return true;
}

// nothing happened
// pass to next handler, if there is one
return false;
}


// handle a new IS_WET state
bool set_IS_WET (body *_body, state &_state) {

// check that the state has only just been actioned
if (_state.status == STARTED) {

//change colour to red (it is on fire, after all)
_body->mEntity->setMaterialName("agcBlue");

if (_body->mNode->numChildren() >0) {

// get the child node of the top cube
SceneNode* mParticleNode = (SceneNode*) _body->mNode->getChild(_body->getName() + "particlefx");

// detach it,
mParticleNode->detachObject(_body->getName() + "fx");

// kill it and
_body->mNode->removeAndDestroyChild(_body->getName() + "particlefx");

// kill the particle system
_body->owner->mSceneMgr->destroyParticleSystem(_body->getName() + "fx");
}


// set the state status to activated
// avoids calling this again
_state.status = ACTIVATED;

// all done
return true;
}

// nothing happened
// pass to next handler, if there is one
return false;
}

};
#endif

betajaen

29-04-2007 22:21:53

Al right, roughly it goes.

bool set_ON_FIRE (body *_body, state &_state) {
if (_state.status == STARTED) {
...
}
else if (_state.status == CLEAR) {

// Destroy your particle system underneath here, and clean it all up, etc.

_status.status = DESTROY;
return true;
}
}

Burkey

29-04-2007 22:25:02

Saving the day once again!

Many thanks :D