MCPcopy Create free account
hub / github.com/axmolengine/axmol / addParticles

Method addParticles

core/2d/ParticleSystem.cpp:730–1112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

728}
729
730void ParticleSystem::addParticles(int count, int animationIndex, int animationCellIndex)
731{
732 if (_paused)
733 return;
734
735 // Try to add as many particles as possible without overflowing.
736 count = MIN(int(_totalParticles * __totalParticleCountFactor) - _particleCount, count);
737
738 animationCellIndex = MIN(animationCellIndex, _animIndexCount - 1);
739 animationIndex = MIN(animationIndex, _animIndexCount - 1);
740
741 int start = _particleCount;
742 _particleCount += count;
743
744 // life
745 for (int i = start; i < _particleCount; ++i)
746 {
747 float particleLife = _life + _lifeVar * _rng.rangef();
748 _particleData.totalTimeToLive[i] = MAX(0, particleLife);
749 _particleData.timeToLive[i] = MAX(0, particleLife);
750 }
751
752 if (_isEmissionShapes)
753 {
754 for (int i = start; i < _particleCount; ++i)
755 {
756 if (_emissionShapes.empty())
757 {
758 _particleData.posx[i] = _sourcePosition.x + _posVar.x * _rng.rangef();
759 _particleData.posy[i] = _sourcePosition.y + _posVar.y * _rng.rangef();
760 continue;
761 }
762
763 auto randElem = _rng.float01();
764 auto& shape = _emissionShapes[MIN(randElem * _emissionShapes.size(), _emissionShapes.size() - 1)];
765
766 switch (shape.type)
767 {
768 case EmissionShapeType::POINT:
769 {
770 _particleData.posx[i] = _sourcePosition.x + shape.x;
771 _particleData.posy[i] = _sourcePosition.y + shape.y;
772
773 break;
774 }
775 case EmissionShapeType::RECT:
776 {
777 _particleData.posx[i] = _sourcePosition.x + shape.x + shape.innerWidth / 2 * _rng.rangef();
778 _particleData.posy[i] = _sourcePosition.y + shape.y + shape.innerHeight / 2 * _rng.rangef();
779
780 break;
781 }
782 case EmissionShapeType::RECTTORUS:
783 {
784 float width = (shape.outerWidth - shape.innerWidth) * _rng.float01() + shape.innerWidth;
785 float height = (shape.outerHeight - shape.innerHeight) * _rng.float01() + shape.innerHeight;
786 width = _rng.rangef() < 0.0F ? width * -1 : width;
787 height = _rng.rangef() < 0.0F ? height * -1 : height;

Callers

nothing calls this directly

Calls 10

getInstanceFunction · 0.85
fill_nFunction · 0.85
rotateByAngleMethod · 0.80
convertToWorldSpaceMethod · 0.80
Vec2Class · 0.70
emptyMethod · 0.45
sizeMethod · 0.45
isZeroMethod · 0.45
atMethod · 0.45
getAngleMethod · 0.45

Tested by

no test coverage detected