void ParticleEmitter::setSpriteFrameCoords(unsigned int frameCount, int width, int height) { GP_ASSERT(width); GP_ASSERT(height); int x; int y; Rectangle* frameCoords = new Rectangle[frameCount]; unsigned int cols = _spriteTextureWidth / width; unsigned int rows = _spriteTextureHeight / height; unsigned int n = 0; for (unsigned int i = 0; i < rows; ++i) { y = i * height; for (unsigned int j = 0; j < cols; ++j) { x = j * width; frameCoords[i*cols + j] = Rectangle(x, y, width, height); if (++n == frameCount) { break; } } if (n == frameCount) { break; } } setSpriteFrameCoords(frameCount, frameCoords); SAFE_DELETE_ARRAY(frameCoords); }
void ParticleEmitter::setTexture(Texture* texture, BlendMode blendMode) { // Create new batch before releasing old one, in case the same texture // is used for both (so it's not released before passing to the new batch). SpriteBatch* batch = SpriteBatch::create(texture, NULL, _particleCountMax); batch->getSampler()->setFilterMode(Texture::LINEAR_MIPMAP_LINEAR, Texture::LINEAR); // Free existing batch SAFE_DELETE(_spriteBatch); _spriteBatch = batch; _spriteBatch->getStateBlock()->setDepthWrite(false); _spriteBatch->getStateBlock()->setDepthTest(true); setBlendMode(blendMode); _spriteTextureWidth = texture->getWidth(); _spriteTextureHeight = texture->getHeight(); _spriteTextureWidthRatio = 1.0f / (float)texture->getWidth(); _spriteTextureHeightRatio = 1.0f / (float)texture->getHeight(); // By default assume only one frame which uses the entire texture. Rectangle texCoord((float)texture->getWidth(), (float)texture->getHeight()); setSpriteFrameCoords(1, &texCoord); }