Jump to content

How does blendModes work in Phaser.Graphics compared to Sprites


Kacper Pietrzak
 Share

Recommended Posts

Hey guys,

Recently I've noticed some strange behaviour while using blendModes on Phaser.Graphics.

I am creating a flashlight by drawing dark rectangle and lighter calculated shape of light from flashlight, I draw that on Phaser.Graphics object. Then I apply this object as a texture to sprite to see the difference between rendered outcomes.

this.shadowTexture = this.player.game.add.graphics( 0, 0 );
this.shadowTexture.blendMode = Phaser.blendModes.MULTIPLY;

this.sprite = this.player.game.add.sprite( 200, 0, this.shadowTexture.generateTexture() );
this.sprite.blendMode = Phaser.blendModes.MULTIPLY;

update(){
 // draw on shadowTexture
 ...

 this.sprite.texture = this.shadowTexture.generateTexture();
 // just for test purposes
}

this code results in such situation:

Screenshot_2017-07-16_23-44-45.png.a0d5907a7de4635f3b2010a2e1e37458.png

As you can see, blendMode used in Phaser.Graphics resulted with darker flashlight and the one used in Phaser.Sprite in lighter.

Am I getting this all totally wrong ? Or is this some kind of a bug ?

What I would like to achieve is the effect that I get using Sprite just by using Phaser.Graphics.

Please, help guys, I am a bit confused here :)

Thanks

Link to comment
Share on other sites

@samme Setting in only on sprite works just fine, but I cannot afford generatingTextue from Phaser.Graphics every frame. Setting it only on Phaser.Graphics and not applying it to sprite but just displaying results in white color not giving a nice transparent flashlight shape, but is not visible at all. Making it darker than pure white results in what you see one the left side of the picture. So, this behaviour is still kind of mystery for me.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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