Jump to content

Search the Community

Showing results for tags 'dynamic lightning'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 1 result

  1. Hey everyone! I've implemented simple dynamic lightning in my project, but what I'm missing is soft light edges effect. This what it looks like now: https://youtu.be/M-idTMGYvsw I use sprites' masks to achieve that, code looks somewhat like this: updateShowingLayer() { + this.showMaskGraphics.clear(); + this.showMaskGraphics.lineStyle( 2, 0xffffff, 1 ); + this.showMaskGraphics.beginFill( 0x00000000 ); + this.showMaskGraphics.moveTo( this.player.x, this.player.y ); + + for ( let i = 0; i < NUMBER_OF_RAYS; i++ ) { + const rayAngle = mouseAngle - ( LIGHT_ANGLE / 2 ) + ( LIGHT_ANGLE / NUMBER_OF_RAYS ) * i; + let lastX = this.player.x; + let lastY = this.player.y; + for ( let j = 1; j <= RAY_LENGTH; j++ ) { + const landingX = Math.round( this.player.x - ( 2 * j ) * Math.cos( rayAngle ) ); + const landingY = Math.round( this.player.y - ( 2 * j ) * Math.sin( rayAngle ) ); + if ( !this.isTileBlocking( landingX, landingY ) ) { + lastX = landingX; + lastY = landingY; + } else { + break; + } + } + this.showMaskGraphics.lineTo( lastX, lastY ); + } + this.showMaskGraphics.lineTo( this.player.x, this.player.y ); + this.showMaskGraphics.endFill(); } } And then I just set masks in corresponding sprites to `this.showMaskGraphics` The full code is available here: https://github.com/PiGames/Project-Nostradamus/blob/dynamic-lightning/src/objects/Flashlight.js Does anyone have an idea how to make this light soft ? Thanks
×
×
  • Create New...