MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!

Started by monkey0506, Mon 12/02/2007 08:11:12

Previous topic - Next topic

Akril15

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

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:

Akril15

Quote from: monkey_05_06 on Tue 15/05/2012 21:22:45
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);

Khris

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.

monkey0506

Well just to confirm, this is the code that's generating the actual effect:

Code: ags

  this.ScreenSprite = DynamicSprite.CreateFromExistingSprite(this.BeamSprite.Graphic, true); // grab the beam sprite
  this.ScreenSprite.Resize(FloatToInt(r * 2.0), FloatToInt(r * 2.0)); // resize the beam sprite to the appropriate radius
  this.ScreenSprite.ChangeCanvasSize(System.ViewportWidth, System.ViewportHeight, this.X, this.Y); // resize the sprite, placing the beam at the appropriate position
  Flashlight_SpriteSurface = this.ScreenSprite.GetDrawingSurface(); // get the drawing surface
  Flashlight_SetColor(Flashlight.DrawingColor); // wrapper function to avoid null pointers and such, sets the surface drawing color
  // flood fill the areas surrounding the beam
  if (this.X > 0) Flashlight_DrawRectangle(0, 0, this.X, System.ViewportHeight);
  if ((this.X + FloatToInt(r * 2.0)) < System.ViewportWidth) Flashlight_DrawRectangle(this.X + FloatToInt(r * 2.0), 0, System.ViewportWidth, System.ViewportHeight);
  if (this.Y > 0) Flashlight_DrawRectangle(0, 0, System.ViewportWidth, this.Y);
  if ((this.Y + FloatToInt(r * 2.0)) < System.ViewportHeight) Flashlight_DrawRectangle(0, this.Y + FloatToInt(r * 2.0), System.ViewportWidth, System.ViewportHeight);
  Flashlight_SpriteSurface.Release(); // release the drawing surface
  Flashlight_SpriteSurface = null; // make sure AGS destroys the invalidated pointer
  if (this.IsGUIMode) this.AGSGUI.BackgroundGraphic = this.ScreenSprite.Graphic; // set the GUI background graphic
  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?

Khris

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: ags
function room_Load() {
  cFlashlight.Clickable = false;
  cFlashlight.z = -180;
  cFlashlight.ChangeRoom(player.Room);
}

function room_RepExec(){
  cFlashlight.x = player.x;
  cFlashlight.y = player.y;
  cFlashlight.Baseline = player.Baseline+1;
}


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.

Akril15

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

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

Khris

Quote from: Akril15 on Fri 18/05/2012 05:41:13I 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. :)

Akril15

Quote from: monkey_05_06 on Fri 18/05/2012 07:00:17
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:
Quotefunction 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

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

morganw

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.

SMF spam blocked by CleanTalk