phaser/src/renderer/webgl/gameobjects/Sprite.js

84 lines
2.3 KiB
JavaScript
Raw Normal View History

/**
* Note that 'this' in all functions here refer to the owning object.
* For example the Group, Stage, Sprite, etc. because the render function
* here is mapped to the prototype for the game object.
*/
Phaser.Renderer.WebGL.GameObjects.Sprite = {
2016-10-05 00:25:06 +00:00
TYPES: [
Phaser.Sprite.prototype,
Phaser.Image.prototype,
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);
}
}
}
};