本文整理汇总了C++中ParticleEmitter::setEnergy方法的典型用法代码示例。如果您正苦于以下问题:C++ ParticleEmitter::setEnergy方法的具体用法?C++ ParticleEmitter::setEnergy怎么用?C++ ParticleEmitter::setEnergy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParticleEmitter
的用法示例。
在下文中一共展示了ParticleEmitter::setEnergy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: create
ParticleEmitter* ParticleEmitter::create(Properties* properties)
{
if (!properties || strcmp(properties->getNamespace(), "particle") != 0)
{
GP_ERROR("Properties object must be non-null and have namespace equal to 'particle'.");
return NULL;
}
Properties* sprite = properties->getNextNamespace();
if (!sprite || strcmp(sprite->getNamespace(), "sprite") != 0)
{
GP_ERROR("Failed to load particle emitter: required namespace 'sprite' is missing.");
return NULL;
}
// Load sprite properties.
// Path to image file is required.
const char* texturePath = sprite->getString("path");
if (!texturePath || strlen(texturePath) == 0)
{
GP_ERROR("Failed to load particle emitter: required image file path ('path') is missing.");
return NULL;
}
const char* blendingString = sprite->getString("blending");
TextureBlending textureBlending = getTextureBlendingFromString(blendingString);
int spriteWidth = sprite->getInt("width");
int spriteHeight = sprite->getInt("height");
bool spriteAnimated = sprite->getBool("animated");
bool spriteLooped = sprite->getBool("looped");
int spriteFrameCount = sprite->getInt("frameCount");
int spriteFrameRandomOffset = sprite->getInt("frameRandomOffset");
float spriteFrameDuration = sprite->getFloat("frameDuration");
// Emitter properties.
unsigned int particleCountMax = (unsigned int)properties->getInt("particleCountMax");
if (particleCountMax == 0)
{
// Set sensible default.
particleCountMax = PARTICLE_COUNT_MAX;
}
unsigned int emissionRate = (unsigned int)properties->getInt("emissionRate");
if (emissionRate == 0)
{
emissionRate = PARTICLE_EMISSION_RATE;
}
bool ellipsoid = properties->getBool("ellipsoid");
float sizeStartMin = properties->getFloat("sizeStartMin");
float sizeStartMax = properties->getFloat("sizeStartMax");
float sizeEndMin = properties->getFloat("sizeEndMin");
float sizeEndMax = properties->getFloat("sizeEndMax");
long energyMin = properties->getLong("energyMin");
long energyMax = properties->getLong("energyMax");
Vector4 colorStart;
Vector4 colorStartVar;
Vector4 colorEnd;
Vector4 colorEndVar;
properties->getVector4("colorStart", &colorStart);
properties->getVector4("colorStartVar", &colorStartVar);
properties->getVector4("colorEnd", &colorEnd);
properties->getVector4("colorEndVar", &colorEndVar);
Vector3 position;
Vector3 positionVar;
Vector3 velocity;
Vector3 velocityVar;
Vector3 acceleration;
Vector3 accelerationVar;
Vector3 rotationAxis;
Vector3 rotationAxisVar;
properties->getVector3("position", &position);
properties->getVector3("positionVar", &positionVar);
properties->getVector3("velocity", &velocity);
properties->getVector3("velocityVar", &velocityVar);
properties->getVector3("acceleration", &acceleration);
properties->getVector3("accelerationVar", &accelerationVar);
float rotationPerParticleSpeedMin = properties->getFloat("rotationPerParticleSpeedMin");
float rotationPerParticleSpeedMax = properties->getFloat("rotationPerParticleSpeedMax");
float rotationSpeedMin = properties->getFloat("rotationSpeedMin");
float rotationSpeedMax = properties->getFloat("rotationSpeedMax");
properties->getVector3("rotationAxis", &rotationAxis);
properties->getVector3("rotationAxisVar", &rotationAxisVar);
bool orbitPosition = properties->getBool("orbitPosition");
bool orbitVelocity = properties->getBool("orbitVelocity");
bool orbitAcceleration = properties->getBool("orbitAcceleration");
// Apply all properties to a newly created ParticleEmitter.
ParticleEmitter* emitter = ParticleEmitter::create(texturePath, textureBlending, particleCountMax);
if (!emitter)
{
GP_ERROR("Failed to create particle emitter.");
return NULL;
}
emitter->setEmissionRate(emissionRate);
emitter->setEllipsoid(ellipsoid);
emitter->setSize(sizeStartMin, sizeStartMax, sizeEndMin, sizeEndMax);
emitter->setEnergy(energyMin, energyMax);
//.........这里部分代码省略.........
示例2: controlEvent
void ParticlesGame::controlEvent(Control* control, EventType evt)
{
std::string id = control->getId();
// Handle UI events.
ParticleEmitter* emitter = _particleEmitterNode->getParticleEmitter();
switch(evt)
{
case Listener::VALUE_CHANGED:
if (control == _startRed)
{
Vector4 startColor = emitter->getColorStart();
startColor.x = _startRed->getValue();
emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
}
else if (control == _startGreen)
{
Vector4 startColor = emitter->getColorStart();
startColor.y = _startGreen->getValue();
emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
}
else if (control == _startBlue)
{
Vector4 startColor = emitter->getColorStart();
startColor.z = _startBlue->getValue();
emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
}
else if (control == _startAlpha)
{
Vector4 startColor = emitter->getColorStart();
startColor.w = _startAlpha->getValue();
emitter->setColor(startColor, emitter->getColorStartVariance(), emitter->getColorEnd(), emitter->getColorEndVariance());
}
else if (control == _endRed)
{
Vector4 endColor = emitter->getColorEnd();
endColor.x = _endRed->getValue();
emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
}
else if (control == _endGreen)
{
Vector4 endColor = emitter->getColorEnd();
endColor.y = _endGreen->getValue();
emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
}
else if (control == _endBlue)
{
Vector4 endColor = emitter->getColorEnd();
endColor.z = _endBlue->getValue();
emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
}
else if (control == _endAlpha)
{
Vector4 endColor = emitter->getColorEnd();
endColor.w = _endAlpha->getValue();
emitter->setColor(emitter->getColorStart(), emitter->getColorStartVariance(), endColor, emitter->getColorEndVariance());
}
else if (control == _startMin)
{
emitter->setSize(_startMin->getValue(), emitter->getSizeStartMax(), emitter->getSizeEndMin(), emitter->getSizeEndMax());
}
else if (control == _startMax)
{
emitter->setSize(emitter->getSizeStartMin(), _startMax->getValue(), emitter->getSizeEndMin(), emitter->getSizeEndMax());
}
else if (control == _endMin)
{
emitter->setSize(emitter->getSizeStartMin(), emitter->getSizeStartMax(), _endMin->getValue(), emitter->getSizeEndMax());
}
else if (control == _endMax)
{
emitter->setSize(emitter->getSizeStartMin(), emitter->getSizeStartMax(), emitter->getSizeEndMin(), _endMax->getValue());
}
else if (control == _energyMin)
{
emitter->setEnergy(_energyMin->getValue(), emitter->getEnergyMax());
}
else if (control == _energyMax)
{
emitter->setEnergy(emitter->getEnergyMin(), _energyMax->getValue());
}
else if (control == _emissionRate)
{
emitter->setEmissionRate(_emissionRate->getValue());
}
else if (id == "posX")
{
Vector3 pos(emitter->getPosition());
pos.x = ((Slider*)control)->getValue();
emitter->setPosition(pos, emitter->getPositionVariance());
}
else if (id == "posY")
{
Vector3 pos(emitter->getPosition());
pos.y = ((Slider*)control)->getValue();
emitter->setPosition(pos, emitter->getPositionVariance());
}
else if (id == "posZ")
{
Vector3 pos(emitter->getPosition());
//.........这里部分代码省略.........