Jump to content

Overriding Sprite.render?


diwil
 Share

Recommended Posts

I'm working on a game with dynamic lighting (sprite based), and I've stumbled across a problem with rendering sprites to a RenderTexture. Is there any way to override the default render() method for Phaser.Sprite objects?

 

I'm basically using a camera-fixed sprite called Darkness, rendered in PIXI.blendMode.MULTIPLY, which has a filled rectangle of my ambient color called ambience in it's properties. I also have a group of light sprites, that I render to the darkness' renderTexture. I need to use a Group so renderXY takes rotation into account.

function render(){	// Clear the darkness sprite	darkness.renderTexture.renderXY(darkness.ambience, 0, 0, true);	// Render lights	darkness.renderTexture.renderXY(lightGroup, -game.camera.x, -game.camera.y, false);}

 However, this causes the lights to be drawn to the renderTexture as well as the scene itself. Is there a way to disable rendering of the sprite, while still letting me use renderXY to paint it on a renderTexture, with rotation? I tried changing the renderable and visible properties, but setting either one to false caused the lights to stop rendering altogether.

Link to comment
Share on other sites

I worked it out after all!  :D

 

I had to set the lightGroup.visible to false in the state's preRender() method, and enable visibility in the render() method before the renderXY() call.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...