Author Topic: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!  (Read 37127 times)

I'm sorry for resurrecting the thread, but I had a question about the module that I felt would be best asked here:

I'm using Flashlight's FollowCharacter setting (in GUI mode), and while the module itself works wonderfully, I can't figure out a way to get the beam to "acknowledge" walk-behinds. Whenever the character walks behind one, the beam shines "through" the walkbehind, as if the solid wall the character was behind were transparent. In the case of walkbehinds in the foreground, I think I can create another large GUI to overlap the flashlight beam, but how can I get it to acknowledge smaller walkbehinds that the character can walk both behind and in front of?

I did a search on the forums, and all I could find was a references to a "mask" feature for a much older version of this module (back when it was just a plugin). I'd like to know if there's anything I can do to make the beam to be concealed by a walkbehind using this module before I try out the plugin.

Thanks!

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
The module isn't doing anything that should be affecting walkbehinds. This is actually the first I'd heard of that. All it's basically doing is resizing a dynamic sprite (the beam sprite) and then flood-filling the surrounding area. GUI background graphics shouldn't be affecting walkable areas at all...?

I can maybe look into it more, but I'm kind of baffled what would be causing this...... :confused: :undecided:

The module isn't doing anything that should be affecting walkbehinds. This is actually the first I'd heard of that. All it's basically doing is resizing a dynamic sprite (the beam sprite) and then flood-filling the surrounding area. GUI background graphics shouldn't be affecting walkable areas at all...?

I can maybe look into it more, but I'm kind of baffled what would be causing this...... :confused: :undecided:

Hmm...strange. Maybe I'm doing something wrong. Here's the code I'm using (in just one room for now):
Quote
// player enters room before fade-in
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(3728, true); //sprite 3728 uses an alpha channel, BTW.
Flashlight.Enabled = true;
Flashlight.SetGUIMode(gFlashlight, sprite);
Flashlight.Transparency = 10;
Flashlight.Radius = 90.0;
Flashlight.SetFollowCharacter(cEgo, true);

Well, isn't the module using a GUI to display the flashlight sprite? GUIs are displayed above everything else, and there's no way to show them behind walkbehinds.
For a flashlight sprite to acknowledge walkbehinds, it has to be implemented as a Character.

Actually, putting the sprite in the first (and second?) frame of the first four loops and calling cFlashlight.FollowCharacter(player, FOLLOW_EXACTLY, 0); should do it.
Fail at Floaty Rog' now!  still having to deal with what games are going through

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Well just to confirm, this is the code that's generating the actual effect:

Code: Adventure Game Studio
  1.   this.ScreenSprite = DynamicSprite.CreateFromExistingSprite(this.BeamSprite.Graphic, true); // grab the beam sprite
  2.   this.ScreenSprite.Resize(FloatToInt(r * 2.0), FloatToInt(r * 2.0)); // resize the beam sprite to the appropriate radius
  3.   this.ScreenSprite.ChangeCanvasSize(System.ViewportWidth, System.ViewportHeight, this.X, this.Y); // resize the sprite, placing the beam at the appropriate position
  4.   Flashlight_SpriteSurface = this.ScreenSprite.GetDrawingSurface(); // get the drawing surface
  5.   Flashlight_SetColor(Flashlight.DrawingColor); // wrapper function to avoid null pointers and such, sets the surface drawing color
  6.   // flood fill the areas surrounding the beam
  7.   if (this.X > 0) Flashlight_DrawRectangle(0, 0, this.X, System.ViewportHeight);
  8.   if ((this.X + FloatToInt(r * 2.0)) < System.ViewportWidth) Flashlight_DrawRectangle(this.X + FloatToInt(r * 2.0), 0, System.ViewportWidth, System.ViewportHeight);
  9.   if (this.Y > 0) Flashlight_DrawRectangle(0, 0, System.ViewportWidth, this.Y);
  10.   if ((this.Y + FloatToInt(r * 2.0)) < System.ViewportHeight) Flashlight_DrawRectangle(0, this.Y + FloatToInt(r * 2.0), System.ViewportWidth, System.ViewportHeight);
  11.   Flashlight_SpriteSurface.Release(); // release the drawing surface
  12.   Flashlight_SpriteSurface = null; // make sure AGS destroys the invalidated pointer
  13.   if (this.IsGUIMode) this.AGSGUI.BackgroundGraphic = this.ScreenSprite.Graphic; // set the GUI background graphic
  14.   else if (this.IsOverlayMode) this.AGSOverlay = Overlay.CreateGraphical(0, 0, this.ScreenSprite.Graphic, true); // set the overlay graphic

So, are you sure this is the root cause? If so then there might actually be a bug in the way AGS is rendering walk-behinds...but I'm somewhat doubtful about that.

Edit: Khris posted while I was typing this...and he seems to be reading the issue rather differently than I am. GUIs are drawn on top of any room backgrounds, then for a walk-behind area, the room background is drawn, then characters, from front to back. Are you saying you want the flashlight beam to actually appear behind the walk-behind area as well?

I'm sure that's what Akril was saying.
I did a quick test using this sprite:


I put it in a new view/character and used:
Code: Adventure Game Studio
  1. function room_Load() {
  2.   cFlashlight.Clickable = false;
  3.   cFlashlight.z = -180;
  4.   cFlashlight.ChangeRoom(player.Room);
  5. }
  6.  
  7. function room_RepExec(){
  8.   cFlashlight.x = player.x;
  9.   cFlashlight.y = player.y;
  10.   cFlashlight.Baseline = player.Baseline+1;
  11. }

Works fine.

The only thing left to do to drive home the effect is to use non-clickable objects instead of walk-behinds and switch their graphic from light to dark, depending on the player standing behind them or not.
Fail at Floaty Rog' now!  still having to deal with what games are going through

Yes -- I wanted the beam to react to walkbehinds the same way that the player it was following did, and since no one else has brought up this problem, I thought that I might have overlooked something in the manual.

I never thought of the idea of using a flashlight "character" to follow the player around before. I tried making one, but it doesn't seem to work very well -- when the character goes behind a walk-behind, the flashlight character goes behind it as well, making the walkbehind suddenly much brighter than the space behind it. The mask also disappears when the icon bar pops up (probably due to the Z-order, I'm guessing).

However, I managed to come up with a workaround using the GUI method: I got the GUI's beam sprite to change to a completely dark mask when the character steps on a region positioned behind a walkbehind, then back to the standard beam when he steps off of the region. Since the walkbehind is a large, solid wall that hides the entire character, this works fairly well.

I'm now running into some slight problems with the flashlight not "turning on" when I start the game until the room is fully loaded, but I should hopefully be able to find a workaround for that too.

Thank you for your help, monkey_05_06 and Khris!

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
I think you can actually call Flashlight.Update() in room_Load to draw the flashlight effect before the room is faded in. Could be remembering that wrong, it's been over 3 years since I last updated this module. :P

I tried making one, but it doesn't seem to work very well -- when the character goes behind a walk-behind, the flashlight character goes behind it as well, making the walkbehind suddenly much brighter than the space behind it.
This is expected, and the reason why I added the last paragraph to my previous post. :)
Fail at Floaty Rog' now!  still having to deal with what games are going through

I think you can actually call Flashlight.Update() in room_Load to draw the flashlight effect before the room is faded in. Could be remembering that wrong, it's been over 3 years since I last updated this module. :P
There is actually some code in Flashlight.asc that seem to do just that:
Quote
function repeatedly_execute() {
 Flashlight.Update();
}

function on_event(EventType event, int data) {
 if (event == eEventEnterRoomBeforeFadein)  Flashlight.Update();
}
But unfortunately, it only seems to work if I go from one room with the flashlight turned on to another with the flashlight turned on. Still, I should be able to find a way to fix this, since it's not crucial that the flashlight is turned on in that first room.

Voedino

  • New Game - 2021
Error in new version AGS 3.5.0 with this plugin.

Flashlight_2_0_BETA_2.asc(38): Error (line 38): '.ViewportWidth' is not a public member of 'System'. Are you sure you spelt it correctly (remember, capital letters are important)?

In the old version 3.4.1.15 this plugin worked without problems

https://adventuregamestudio.github.io/ags-manual/UpgradeTo35.html#new-screen-struct

obsolete propertyreplace with
System.ScreenWidthScreen.Width
System.ScreenHeightScreen.Height
System.ViewportWidthScreen.Width
System.ViewportHeightScreen.Height

You can either use the new values or change the setting of Script Compatibility Level in general settings.