Guest User

Untitled

a guest
Jul 22nd, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. export default class TilemapVisibility {
  2. constructor(shadowLayer) {
  3. this.shadowLayer = shadowLayer;
  4. this.activeRoom = null;
  5. }
  6.  
  7. setActiveRoom(room) {
  8. // We only need to update the tiles if the active room has changed
  9. if (room !== this.activeRoom) {
  10. this.setRoomAlpha(room, 0); // Make the new room visible
  11. if (this.activeRoom) this.setRoomAlpha(this.activeRoom, 0.5); // Dim the old room
  12. this.activeRoom = room;
  13. }
  14. }
  15.  
  16. // Helper to set the alpha on all tiles within a room
  17. setRoomAlpha(room, alpha) {
  18. this.shadowLayer.forEachTile(
  19. t => (t.alpha = alpha),
  20. this,
  21. room.x,
  22. room.y,
  23. room.width,
  24. room.height
  25. );
  26. }
  27. }
Add Comment
Please, Sign In to add comment