phaser/src/gameobjects/sprite/SpriteWebGLRenderer.js

78 lines
2.1 KiB
JavaScript
Raw Normal View History

Phaser.Renderer.WebGL.GameObjects.Sprite = {
2016-10-05 00:25:06 +00:00
TYPES: [
Phaser.GameObject.Sprite.prototype,
2016-10-05 00:25:06 +00:00
PIXI.Sprite.prototype
],
render: function (renderer, src)
{
// If the sprite is not visible or the alpha is 0 then no need to render this element
2016-10-05 00:25:06 +00:00
if (!src.visible || src.alpha === 0 || !src.renderable)
{
return;
}
// Add back in: || src.texture.crop.width <= 0 || src.texture.crop.height <= 0
var i;
// Would be good to get this down to 1 check, or even none.
2016-10-05 00:25:06 +00:00
if (src._mask || src._filters)
{
var spriteBatch = renderer.spriteBatch;
// push filter first as we need to ensure the stencil buffer is correct for any masking
2016-10-05 00:25:06 +00:00
if (src._filters)
{
spriteBatch.flush();
2016-10-05 00:25:06 +00:00
renderer.filterManager.pushFilter(src._filterBlock);
}
2016-10-05 00:25:06 +00:00
if (src._mask)
{
spriteBatch.stop();
2016-10-05 00:25:06 +00:00
renderer.pushMask(src.mask);
spriteBatch.start();
}
// add this sprite to the batch
2016-10-05 00:25:06 +00:00
spriteBatch.render(src);
// now loop through the children and make sure they get rendered
for (i = 0; i < this.children.length; i++)
{
2016-10-05 00:25:06 +00:00
var child = src.children[i];
child.render(renderer, child);
}
// time to stop the sprite batch as either a mask element or a filter draw will happen next
spriteBatch.stop();
2016-10-05 00:25:06 +00:00
if (src._mask)
{
2016-10-05 00:25:06 +00:00
renderer.popMask(src._mask);
}
2016-10-05 00:25:06 +00:00
if (src._filters)
{
renderer.filterManager.popFilter();
}
spriteBatch.start();
}
else
{
2016-10-05 00:25:06 +00:00
renderer.spriteBatch.render(src);
// Render children!
2016-10-05 00:25:06 +00:00
for (i = 0; i < src.children.length; i++)
{
2016-10-05 00:25:06 +00:00
var child = src.children[i];
child.render(renderer, child);
}
}
}
};