Adventure Game Studio

AGS Support => Modules, Plugins & Tools => Topic started by: monkey0506 on Mon 12/02/2007 08:11:12

Title: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Mon 12/02/2007 08:11:12
v2.0 [FINAL] Update

Now presenting: The version change nearly 2 years in the making...Flashlight v2.0! :=

This should be the most stable and functional version of the module ever! It does now require AGS 3.1.2*, but there's a good cause. Alpha channeled beam sprites with transparency are incredible!

Due to this change in AGS, I highly recommend using GUI mode. Overlay mode does not support alpha channels or transparency. And of course to use alpha channels you would also have to be in 32-bit. But the effect is completely worth it! For information on setting up the GUI, RTFM (http://www.americangirlscouts.org/w/index.php?title=Flashlight&#Setup)

Alpha sprites+transparency was the major difference between this module and the previous plugin. Now thanks to CJ's dedication, you don't have to compromise! ;D

Download Flashlight v2.0 (http://meleepta.x10hosting.com/Flashlight_2_0.rar) [FINAL]
Mirror (http://monkey.05.06.googlepages.com/Flashlight_2_0.rar)
Read the Flashlight manual online (http://americangirlscouts.org/agswiki/Flashlight) (NOTE: Last updated with v2.0 BETA 3)

Hopefully I'll find time soon(-ish) to update the demo.

- monkey

*I have received confirmation that the module will work with AGS versions as early as 3.0.2 without problem (provided the #ifver is updated). The reason for this requirement was to allow the awesomeness to abound, but if you're using a prior version and don't want to upgrade, give it a shot...

NEW! Alpha channeled sprite with partial transparency!
(http://img61.imageshack.us/img61/1504/screenxj3.png)
Title: Re: MODULE: Flashlight v1.0
Post by: Gilbert on Mon 12/02/2007 08:50:58
Good work!
I'll move this to archive section.
Title: Re: MODULE: Flashlight v1.0
Post by: Lt. Smash on Mon 12/02/2007 11:27:28
Thanks!
That's exactly what I need.

But I have some questions:

Is there a way to make that black overlay a bit transparent?
Is it possible to draw some shades into that bmp, like they were in the other plugin?
Is it possible to use a normal sprite instad of that file?
And how did you name that dynamic sprite(flashlight) because I want to delete it, when quitting game? (sprite.delete())

EDIT:
I also found a bug:
When I'm using Flashlight.CharacterToFollow and I'm in a room (640x200) which is larger than the screen resolution, then the flashlight goes away from the character.(If I'm scrolling)
Title: Re: MODULE: Flashlight v1.0
Post by: Da_Elf on Mon 12/02/2007 16:45:59
i too use scrolling rooms alot. how this gets addressed. if it does work out then i will definately be downloading this.

EDIT

i cant download. both left click and right click "save as" give me an html file to save.

EDIT EDIT

never mind. was aproblem with my browser i guess

EDIT EDIT EDIT hehe

can you by anychance post a quick demo scene on how its used?
Title: Re: MODULE: Flashlight v1.0
Post by: monkey0506 on Mon 12/02/2007 18:45:08
I take a DynamicSprite of the top-left pixel of the flashlight sprite to create the surrounding black Overlays. Also the flashlight sprite is loaded dynamically (at the moment). And there's currently no way to make a DynamicSprite partially transparent. Nor is there a way to make an Overlay partially transparent. So, in short, no.

You can replace the "flashlight.bmp" file with your own custom "flashlight.bmp" if you'd like. So if you want shades drawn into the image you can simply replace the file with your custom image. The default image was just something I made simply for testing and showing the module at work.

I will look into the bug with scrolling rooms, however I use the Character.x and Character.y variables directly so I see no reason why there should be a problem. According to the manual these are room co-ordinates, so I'm not sure what's gone amiss, though I will look into it.

I will also take a look at allowing the user some access to the sprite so you can use a copy of a static sprite instead of requiring the use of the external file. Additionally this will allow you to delete the sprite to suppress error messages with AGS versions prior to 2.72.

[EDIT:]

I think I've thought this through backwards. I think Overlays use screen co-ordinates which would explain the error with scrolling rooms (since the Character.x/y variables are room co-ordinates). I'll fix this. ;)

@Da_Elf's EDIT Mark III: I think that would be a reasonable request. But for some reason my brain isn't working and I can't seem to figure out how to convert ROOM co-ordinates into SCREEN co-ordinates. :-X

Wait...never mind. It's just the room co-ordinates minus the Viewport X/Y. D'oh! I'm going to try and find a scrollable background here just to test that it is working, and then I should be able to upload v1.5. And a demo as well.
Title: Re: MODULE: Flashlight v1.0
Post by: Lt. Smash on Mon 12/02/2007 19:28:39
QuoteI take a DynamicSprite of the top-left pixel of the flashlight sprite to create the surrounding black Overlays. Also the flashlight sprite is loaded dynamically (at the moment). And there's currently no way to make a DynamicSprite partially transparent. Nor is there a way to make an Overlay partially transparent. So, in short, no.
wouldn't it be possible with RawDrawImageTransparent if the picture is in the sprite manager?
Title: Re: MODULE: Flashlight v1.0
Post by: monkey0506 on Mon 12/02/2007 19:44:20
RawDrawImageTransparent (as with all the RawDraw functions) draws onto the room background. So any characters and objects in the room would appear to be on top of the darkened areas. So that wouldn't really work out too well.

But I did get the bug with scrolling rooms worked out in the new version which I'll be uploading shortly. I also corrected my error with using the "Radius" parameter as a diameter (the property is still Flashlight.Radius, but it is now a float and the radius instead of the int diameter used by v1.0). I've made the DynamicSprite (Flashlight.Sprite) writeprotected, so you now have read access (this allows you the ability to use Flashlight.Sprite.Delete()), and I've included a Flashlight.SetSprite function so you can use existing sprites.
Title: Re: MODULE: Flashlight v1.5 - Now with demo!
Post by: Da_Elf on Wed 14/02/2007 19:57:55
here are the bugs i found.
For some reason i couldnt use the flashlight without the keypresses. i tried to type my code as such due to the fact that i dont want to give control to the light by keypresses. this is for my character when he is in a dark area with or without a flaming torch


#sectionstart room_fÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_f() {
Ã,  // script for Room: Player enters room (before fadein)
Flashlight.Enabled = !Flashlight.Enabled; // toggle Flashlight on/off
Flashlight.CharacterToFollow = player; // Flashlight follows player
if (GetGraphicalVariable("torch") == 0) {
Flashlight.Radius == 0;
}
else {
Ã,  Ã,  Ã,  Ã, Flashlight.Radius == 70:
Ã,  Ã,  Ã,  Ã, }
}
#sectionend room_fÃ,  // DO NOT EDIT OR REMOVE THIS LINE


also i my character is in a room where he scales as well and the circle is centered way over his head when he is small.

the last part is that when he changed rooms the overlay would start strobing, then when i quit there was a message saying that some errors were generated while i was testing the game....

(in rom1):Dynamic Sprite 68 was never deleted
Title: Re: MODULE: Flashlight v1.5 - Now with demo!
Post by: Rui 'Trovatore' Pires on Wed 14/02/2007 23:02:09
Whee, problem when playing the demo.

---------------------------
Adventure Game Studio
---------------------------
A fatal error has been generated by the script using the AbortGame function. Please contact the game author for support.

in Flashlight (line 33)
from Flashlight (line 85)

Error: Error enabling Flashlight module: Flashlight.Sprite null. Game aborted.

---------------------------
OKÃ,  Ã, 
---------------------------

I just got on the game and pressed tab.
Title: Re: MODULE: Flashlight v1.5 - Now with demo!
Post by: Da_Elf on Wed 14/02/2007 23:55:03
that ones simple. just add the bmp file to the compile folder of the demo.
Title: Re: MODULE: Flashlight v1.5 - Now with demo!
Post by: monkey0506 on Thu 15/02/2007 03:23:28
Ah...I forgot to put the BMP in the demo package. Sorry about that. My mistake and sincerest apologies.

Regarding your code Da_Elf:

#sectionstart room_f  // DO NOT EDIT OR REMOVE THIS LINE
function room_f() {
  // script for Room: Player enters room (before fadein)
  Flashlight.Enabled = true; // turn flashlight on, toggling would turn it off if it was already on
  Flashlight.CharacterToFollow = player; // Flashlight follows player
  if (GetGraphicalVariable("torch") == 0) {
    Flashlight.Radius = 0.0; // changed int 0 to float 0.0
  }
  else {
    Flashlight.Radius = 70.0; // changed int 70 to float 70.0 and colon ( : ) to semicolon ( ; ).
  }
}
#sectionend room_f  // DO NOT EDIT OR REMOVE THIS LINE


That should work (except for the Scaling issue which I hadn't previously considered).

[EDIT:]

I've re-uploaded the demo. It now includes a QuitFlashlightDemo function. Use this instead of the QuitDemo function. I've also included a Compiled folder which actually only contains the "flashlight.bmp" file.

You can now open the game in AGS and simply press Ctrl+T to try out the demo. And I don't want any complaining about me not releasing the demo as a compiled EXE. I did it this way on purpose so that you could read through the code and figure out how I worked these things through. :P
Title: Re: MODULE: Flashlight v1.6 - Now with demo!
Post by: GarageGothic on Thu 15/02/2007 12:44:02
Using five overlays plus not being able to use transparency? This doesn't seem very efficient. I take your original post about not being able to use overlays as they can't be bigger than 320 to mean that you moved the entire GUI around?

What if, on the other hand, you instead had a GUI with five buttons - a middle one using the flashlight mask sprite, and the four surrounding buttons entirely black? Their positions and sizes could then be adjusted accordingly so the edge sprites always aligned to the center one. This would allow you to do any degree of transparency.
Title: Re: MODULE: Flashlight v1.6 - Now with demo!
Post by: Da_Elf on Thu 15/02/2007 14:27:56
and what about the problem when the gui starts strobbing when i change rooms with the flashlight still on.

plus is the room scaling going to be an issue? i use it alot in my game.
Title: Re: MODULE: Flashlight v1.6 - Now with demo!
Post by: monkey0506 on Fri 16/02/2007 07:43:06
Quote from: GarageGothic on Thu 15/02/2007 12:44:02
Using five overlays plus not being able to use transparency? This doesn't seem very efficient. I take your original post about not being able to use overlays as they can't be bigger than 320 to mean that you moved the entire GUI around?

What if, on the other hand, you instead had a GUI with five buttons - a middle one using the flashlight mask sprite, and the four surrounding buttons entirely black? Their positions and sizes could then be adjusted accordingly so the edge sprites always aligned to the center one. This would allow you to do any degree of transparency.

Hmmm...yes...for some reason I hadn't thought it through like this. I've gotten it mostly worked out, except when nearing the edges of the screen I'm crashing with an error saying that GUIControls must have a size of at least 2x2. So I suppose that implementing a simple check that I'm not trying to set them any smaller than that should get rid of this error.

And I'll probably try to keep some of the old code in-tact so that if the GUI isn't present, it can use Overlays instead.

Anyway, more testing is in order for now. But thank you for pointing my mind in the right direction. I swear, sometimes I think if my skull wasn't so hard my mind would have broken out and wandered off to play in traffic somewhere...

[EDIT:]

@Da_Elf - The scaling issue has already been fixed:

Quotev1.6 Update

I fixed the issue with Character scaling levels.

However I haven't had the chance (and/or haven't taken the time... ;)) to look at this strobing issue yet. I'll have to take a look at exactly what's happening, but if it's what I'm imagining, it should be relatively easy to fix.

First however, I'm in desperate need of some sleep that I haven't been getting (notice the timestamps on the changelog... 8)). So I haven't forgotten it, and I'll see what I can do to get it fixed.
Title: Re: MODULE: Flashlight v2.0 BETA
Post by: Lt. Smash on Fri 16/02/2007 19:43:03
when using the new 2.0 beta i get an error message:

ERROR (line 12): 'Follow Character' is already defined  //in Flashlight header

I hope you can fix it.

question:
is it possible to use an png as the flashlight, which is already transparent(alpha blended sprite) and has a black transparent  gradient?

like this?
(http://666kb.com/i/alw5jh5s8q7ulmqyi.gif)
Title: Re: MODULE: Flashlight v2.0 BETA
Post by: monkey0506 on Fri 16/02/2007 20:41:02
How about: Enforce object-based scripting!

Hehehe...I didn't think about the fact that Character.FollowCharacter used to be just FollowCharacter, and the compiler can't handle both a global FollowCharacter function and a Flashlight.FollowCharacter function (unless the latter was declared first apparently (which isn't possible as the first is internal)).

I'm uploading v2.0 BETA 2 now which is identical except that if you haven't checked "Enforce object-based scripting" then Flashlight.FollowCharacter will be known as Flashlight.SetCharacterToFollow. The script-autocomplete will detect the correct version of the function (thanks to its cunning ability to detect the STRICT macro!).

As for the PNG, as long as you can import it into AGS then you can use it. Import the sprite into the Sprite Manager, then do something like this:

// game_start
Flashlight.SetSprite(DynamicSprite.CreateFromExistingSprite(42)); // 42 would be the slot number for your sprite
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Fri 16/02/2007 21:31:45
I'm confused. how do i set my character to follow manually if the functions been locked. everytime i try to compile my scene when using Flashlight.CharacterToFollow = cEgo; i get an error about the variable 'FlashlightType::CharacterToFollow' is write protected.


the other problem i have since currently my flashlight is stuck on the pointer and not on the character is when I'm using a radius of 0 (to simulate the torch being burnt out.) i get some of the darkness missing
(http://www.elfpro3d.com/Asterix/flight.jpg)

plus I'm also still getting strobbing when changing rooms
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Lt. Smash on Sat 17/02/2007 15:09:59
QuoteAs for the PNG, as long as you can import it into AGS then you can use it. Import the sprite into the Sprite Manager, then do something like this:

Code:
// game_start
Flashlight.SetSprite(DynamicSprite.CreateFromExistingSprite(42)); // 42 would be the slot number for your sprite

that don't work.

I think the problem is, that currently only bmp and pcx can be loaded as a dynamic sprite.
So it would be better if the sprite will be used as the buttons normal graphic and not as a dynamic sprite.

Then it would be possible to use every format(if its supported from the editor) and it would be possible to use an already transparent picture.

EDIT:

using Flashlight.Sprite.Delete(); only the flashlightsprite will be deleted but there are also 5 other dynamic sprites, which won't be deleted.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: GarageGothic on Sat 17/02/2007 15:45:41
Da_Elf, have you tried using Flashlight.FollowCharacter(cEgo) instead?

Lt. Smash, what do you mean that DynamicSprites only can be created from bmp and pcx? Perhaps there's some mistake in the module code, so it doesn't work for that reason, but DynamicSprites can certainly be created from existing sprites.
There would be some trouble combining a 32-bit png with alpha channels and a GUI using transparency though, since alpha channels an the transparency setting are incompatible.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Sat 17/02/2007 16:03:10
that worked. the autocomplete kept giving me charactertofollow as an option.

im still getting the other two problems though. the one with the image i posted above im assuming has something to do with the fact that my game is 640x480 and maybe this code was designed for 320x240 or something like that.
as for the strobing it doesnt happen all the time. when i load the game in the 1st room everythings fine. however when i go into the next room all of the black pieces start to strobe on and off. sometimes i can walk through 3 rooms with no strobing then poof starts to strobe again
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Sat 17/02/2007 16:18:28
Hmmm...I forgot about deleting the DynamicSprites I had to create to make the GUI version work. I'll set up a function to delete all the sprites instead.

Previously I had thought that Overlays could support alpha channels, but I'm wrong. The GUI version should support sprites with an alpha channel, although apparently you can't use the transparency if you do this?

I'll look into this to see what can be done about it.

As for Flashlight.CharacterToFollow, GarageGothic pointed out to use the Flashlight.FollowCharacter (if "Enforce object-based scripting" is turned on, Flashlight.SetCharacterToFollow if it is not) function instead. I had to change this to keep track of when the flashlight was supposed to be following the player (which can change) instead of just one Character.

I'll also look into your trying to set the radius to 0, however you must note that 1) the radius is a float (http://americangirlscouts.org/agswiki/Script_language_keywords#Data_types), not an int, so you must set it to 0.0, and 2) there is an enumerated value eFlashlight_MinimumRadius* which defines the minimum radius of your beam. If you try to set the radius any smaller than this, it will automatically be resized. However, I don't see why that would cause this problem, so I will look into it for you.

[EDIT:]

@Da_Elf:
If you would read the documentation (or any of what I have said) you would realize that if you do not have "Enforce object-based scripting" turned on, you will NOT have the Flashlight.FollowCharacter option available. Instead you will have Flashlight.SetCharacterToFollow. Seeing as you said it worked, I can only assume that you actually did turn this option on, however, you still failed to read the parts I've written about the changes made to the way this property is set. Also, if you had noticed, the autocomplete will show you that Flashlight.CharacterToFollow is now read-only (writeprotected). See the red X over the symbol by the property? That means you can't write this property directly!

I get no problems when setting the radius to 0.0 (with the code in-tact as distributed (eFlashlight_MinimumRadius set to 2)). Changing eFlashlight_MinimumRadius to 0 and then trying to set the radius to 0.0 did however generate errors. The DynamicSprite must be resized to a width and height greater than 0 pixels. I'm currently looking into how to fix this.

As for the strobing issue, I can't replicate it. Maybe if you posted the exact code to tell me exactly what you've done I can find a problem.

*Although this is defined, by default, as 2 (an integer type), it will automatically be converted to a floating-point decimal to be consistent with the Flashlight.Radius property. I cannot, however, convert this value if you are trying to manually set the Flashlight.Radius property to an integer, which should produce errors.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Lt. Smash on Sat 17/02/2007 16:45:51
It would be a bit of work, but if you use a second gui with no transparency as the flashlight gui(the other one as the background gui), it would probably be possible to use alpha transparency and the transparent background at the same time. Or am I wrong?
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: GarageGothic on Sat 17/02/2007 17:11:51
I haven't checked out the code, but if you still create the other black sprites by cropping the top left pixel from the cone sprite and then resizing it, it should retain any alpha channel (for that pixel) present in the original. Thus, if the edges of the original cone sprite is created to be 50% transparent, the other buttons should also be 50% transparent due to the alpha channel.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Sat 17/02/2007 17:52:05
all I'm doing is using the code

Flashlight.Enabled = true;
Flashlight.FollowCharacter(cEgo);
if (GetGraphicalVariable("torch") == 0) {
Ã,  Ã,  Flashlight.Radius = 0.0;
Ã,  }
Ã,  else {
Ã,  Ã,  Flashlight.Radius = 50.0;
Ã,  }

in the when player enters room before face in.
Then when my character walks from one room into another room i get this flashing of the elements that make up the dark area

here is the compiled game with it srobing, walk down to get to the next room and in that room walk left.
also is a template of the game. (this isnt my full game its just a recreation with 2 rooms)
http://www.elfpro3d.com/Asterix/Flashing.exe
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Sat 17/02/2007 18:03:32
As best as I can tell, DynamicSprites apparently don't support alpha channels. I've imported a sprite with an alpha channel, and have used it as a static sprite without any problems, however, as soon as I make a DynamicSprite from it, I lose the alpha transparency.

It's essential to use a DynamicSprite in order to allow the radius of the flashlight beam to be changed. Otherwise you would have to use a different static sprite for each and every size you wanted your beam to be.

So I guess that this won't, in fact, support alpha channels at all. I'm sorry for saying it did without actually testing it. 'Cause we all know what happens when we make assumptions. Poor, poor Mumptions (http://ctrlaltdel-online.com/comic.php?d=20030306).

As I've said, I can't seem to replicate either of Da_Elf's errors, so until he posts some code, I suppose my work here is done...unfortunately. :(

[EDIT:]

Okay Da_Elf, I think I've seen something similar to that, but it should have been fixed by the 2.0 BETA 1. The only thing I can think of now to try and help you solve this is to ask that you send me a copy of your game so I can take a look at it...?

P.S., I've already told you that setting the radius to 0.0 won't work. Even if you set eFlashlight_MinimumRadius to 0, your game would crash. So don't expect that bit to magically start working.

Checking the tracker entry here (http://www.adventuregamestudio.co.uk/tracker.php?action=detail&id=527), it would seem DynamicSprites do in fact make use of alpha channels. So can anyone tell me what I've done wrong? Even something as simple as:

DynamicSprite* newMouse = DynamicSprite.CreateFromExistingSprite(28);
mouse.ChangeModeGraphic(eModeWalkTo, newMouse.Graphic);


Shows no alpha transparency, while RawDrawImage(50, 50, 28); does. ???

My initial line of thinking here would be that the alpha channel gets destroyed when I resize the DynamicSprite (as in the module), however, in the above example which shows no alpha channel, I haven't resized it. So that's not actually the issue.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Sat 17/02/2007 18:14:30
opps. you posted while i was typing and i didnt notice. here is what i modified above....

here is the compiled game with it srobing, walk down to get to the next room and in that room walk left.
also is a template of the game. (this isnt my full game its just a recreation with 2 rooms)
http://www.elfpro3d.com/Asterix/Flashing.exe. when i set radius to 0 the game sets it to 2 for me since you set minumin to 2 so thats not the problem even when using 2 the borders of the black areas dont reach the border of the screen

EDIT

the work around i had to use was set radius to 3. setting to 2 gives me the problems i was facing. but 3 and up works fine
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: GarageGothic on Sat 17/02/2007 18:16:16
This is very interesting news to me, monkey. I've been having problems with an alpha-channelled DynamicSprite for some days now, and this could very well be the reason. Well, I've asked CJ to implement a function to remove alpha channels from DynamicSprites, so perhaps it will be possible in the future.

As a workaround for the antialiasing (but too hack'ish to implement in the module, I think), you could let the module handle the totally black areas (still with option of GUI transparency), and then add an alpha'ed sprite for the inner part of the cone as a character in the room. You would of course need to add a bit of code to make that character follow the GUI around.

Edit: Just saw your addition. I'll check it out myself now.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Sat 17/02/2007 18:22:49
@Da_Elf: 404'd!! (http://homestarrunner.com/404.htm) (Edit 1: ) Nevermind. You fixed it. (Edit 2: ) Except...you've included a Compiled folder...but no Compiled EXE. I'll take a look at your AGT file you've included.

@GG: It wouldn't be too hard to set the Character's x and y properties instead of the GUIControl's X and Y ones, I would simply have to check that the Character wasn't moving (via Character.Move) first. I'm also a bit reluctant to require the user to designate a GUI and a Character for the flashlight effect. I'll give it some consideration, though I'm not sure how I'll handle this (for now). Plus, it would be much more difficult to handle the size of the radius this way (I would have to manually determine the proper scaling level for the Character to set the sprite to the correct size). But I'll mull over some thoughts before I make my final decision.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: GarageGothic on Sat 17/02/2007 18:38:39
In regards to using a character - I didn't mean that it was difficult to align character and GUI, I meant it would be a bit of work for Lt. Smash if he was going to use that option. Because, as I also said, it is a bit hack'ish, and I agree with you that it's probably not a good idea to include in the module.
I don't think that the scaling/radius calculation would be very difficult, though the alignment may be off by a pixel or two. It's just a few lines of code:

cFlashlight.ManualScaling = true;
cFlashlight.Scaling = (radius/Game.SpriteHeight[flashsprite])*200;


Of course the vertical/horizontal scaling would have to be the same, but I don't know if the current module even allows them to be set individually. And it can't be bigger than double original size, but usually you don't want to scale sprites up too much anyway.

To follow up on the DynamicSprite issue:

It would actually seem that the alpha channel DOES disappear when the DynamicSprite is created. I could swear that this has been a problem in previous version, but I see nothing in the changelist to indicate that it's been fixed. Very strange. On the other hand I always have many problems with imported alpha'ed sprites, so perhaps this was due to some other conflict. This is an excellent discovery for my purposes, but now I must go add a comment to that tracker entry. Weird.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Lt. Smash on Sat 17/02/2007 18:53:18
I wouldn't bother if I have to use a GUI AND a character.

But wouldn't the whole thing work with RawDraw?
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: GarageGothic on Sat 17/02/2007 18:59:33
RawDraw would draw the darkness behind characters and objects in the room. That was the original problem and the reason for using Overlays.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Lt. Smash on Sat 17/02/2007 19:01:13
Oh yes I forgot that. sorry
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Sat 17/02/2007 19:10:55
GarageGothic: Okay, I understand now. I guess I was just overthinking the scaling (like I was doing when trying to figure out the scrolling issue heheh).

It's good to hear that I'm not just retarded/completely incompetent when it comes to the DynamicSprite issue. Thanks for following up on that.

As for you Da_Elf...I can't seem to figure out what the problem is. I've checked your code...and there...shouldn't be anything wrong with it, though I have seen the problem in action. Trying to replicate the problem in a game I've created independently, I still can't figure out what's wrong.

I'm not giving up on this problem, but I just wanted to give you an update thus far.

[EDIT:]

Only 3 posts while I was reading my brother's *to me* messages on MySpace. Not too shabby. :=
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Lt. Smash on Mon 19/02/2007 19:28:45
only a question:

monkey are you going to make a character for the flashlight as GarageGothic suggested or have you found a simplier solution for that Alpha blended problem?
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Wed 21/02/2007 17:23:50
I haven't yet decided Lt. Smash. It doesn't seem like it's really a good idea...though if it's required for the module I could attempt it. Right now I'm working on my dialog module, and then I intend to work on getting that implemented better into my MonkeyTemplate module...but somewhere I will find time to take a look at this.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Wed 28/02/2007 21:10:36
i give up. ive tried the module with other scenes and i always get that 'flashing" when the character changes room. i cant figure it out.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Tue 20/03/2007 18:58:17
oook. i think i have a solution to my flashing problem. it seemed the flashing starts when i change the room but in the first room its fine. therefore i setup a flashlight variable to let me know if the light is on or off so in the rooms which are supposed to be dark it checks the variable to see if its on. when my character leaves the room i turn off the flashlight but dont change the variable. then on entering the new room i check the variable, see the lights supposed to be on, so i then turn on the light. so in the new room i cant walk into it with the script already working it seems. this work around seems to be fine however the other problem i face which isnt too much of a problem is that i use the script in the "when player enters room before fade in" seems the dynamic sprite doesnt work with fade ins. the room fades in (letting the player see the layout) then it applies the black. like i said, easily fixed by not using fade ins.

EDIT

ok. I'm now trying to add my own piece of code to take care of the scaling issue by using
Flashlight.Radius = (GetScalingAt(player.x, player.y));
now researching how to get a int from a float

EDIT

hmmm. ive used in the past

Display("you have %d senturii", GetGraphicalVariable("getmoney"));

this was all i could find about it in the help file and the wiki but the %d thing doesnt seem to work

EDIT (captians log stardate blah blah blah)

none of the % things seem to be right sigh im just stupid i guess hehe
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Wed 21/03/2007 17:05:39
For several reasons I haven't had much time/energy to devote to AGS for the past several weeks. If I'm reading what you've written correctly, then the strobing error only occurs if you have a fading room transition between two rooms with the flashlight effect enabled? I can take a look to try and see if there's anything I can do to fix this on my part and I'll let you know.

Regarding the "scaling issue" are you wanting the flashlight to be scaled to the height/width (greater of the two) of the Character? Perhaps you could do something like this:

ViewFrame* frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
float fr = IntToFloat(Game.SpriteHeight[frame.Graphic]);
if (Game.SpriteWidth[frame.Graphic] > Game.SpriteHeight[frame.Graphic]) fr = IntToFloat(Game.SpriteWidth[frame.Graphic]);
fr *= (IntToFloat(player.Scaling) / 100.0) / 2.0;
// fr += 1.0;
Flashlight.Radius = fr;


As for your problems with "the % things", you seem to have shown a proper implementation of them. How aren't they working (though this has nothing to do with the module, I'm willing to try and help)? What is happening, and what's not?
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Wed 21/03/2007 17:34:07
The flashing doesnt have anything to do with the fading, it had to do with entering a room when flashlight was turned on in another room. the problem with the fading is a totally different problem. while AGS executes the fade on the room you can see the entire room properly. When its fully faded in then the flashlight effect is added hiding the background. even though i have turned on the flashlight in the "before fadein" area of the room script.

as for the % thing it works in the area where i used it for the displaying the amount of money. however when i tried to use the % to convert fload and int it didnt work
example: Flashlight.Radius = %d (GetScalingAt(player.x, player.y));

i can kinda see where your going with your code but why cant it simply be something to find out what the scaling is where the characters possition is and apply that to the .Radius
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Wed 21/03/2007 19:00:36
The "%d thing" only works in string formatting. You can't just throw it into the script wherever you want.

int int_var = 5;
float float_var = 9.8;
Display("int var: %d", int_var); // display int variable
Display("float var: %f", float_var); // display float variable
int temp_int_var = int_var;
int_var = FloatToInt(float_var); // convert float to int
float_var = IntToFloat(temp_int_var); // convert int to float


Regarding the fading, I understand the issue now, but there's really no way for me to control that. If you're using the Overlay version, you may try using the GUI version, i.e.:

// Script header for module 'Flashlight'

//#define FLASHLIGHT_GUI gFlashlight  // CHANGE THIS
#define FLASHLIGHT_GUI gFlashlight  // TO THIS (WHERE "gFlashlight" IS THE SCRIPT O-NAME OF YOUR FLASHLIGHT GUI)


I'm not sure if that would work as I'm not sure how GUIs react during room transitions...(it's been a while and I don't have time to look)...but it could be worth a try.

It wouldn't make any sense to try and scale the radius of the flashlight based solely on the scaling of the room at any given co-ordinates, unless you really just wanted to force the flashlight to use the scaling of the room.

The way you're trying to implement it takes no consideration for the possibility of manual character scaling, and you haven't even actually applied the scaling to a base value, you're just *attempting* directly setting the radius to the scale at the room co-ordinates.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: Da_Elf on Wed 21/03/2007 19:52:09
well reason I'm trying this way is because in these rooms where the flashlight will be used there will be no manual scaling, only room scaling. so since I'm using the one where the flashlight (flameing torch) is lighting around the character then where he goes it follows and i need it to scale along with him. once i got it working then i was going to add an extra equation to have the light at the right pixel scale to room scale ratio.

basically I'm trying to simplify this entire thing to something my brain can handle hehe
ive got this code to work now.
#sectionstart room_fÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_f() {
Ã,  // script for Room: Player enters room (before fadein)
Cacosing(1, 274, 265);
Ã,  Flashlight.Enabled = true;
Flashlight.FollowCharacter(cEgo);Ã,  Ã, 
}
#sectionend room_fÃ,  // DO NOT EDIT OR REMOVE THIS LINE

#sectionstart room_gÃ,  // DO NOT EDIT OR REMOVE THIS LINE
function room_g() {
Ã,  // script for Room: Repeatedly execute
Flashlight.Radius = IntToFloat(GetScalingAt(player.x, player.y));
}
#sectionend room_gÃ,  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Thu 22/03/2007 04:03:23
The way you're implementing it right now, you're just setting the flashlight's radius (note radius, not diameter) to the scale where the player is standing. So if the player is scaled at 100% then the radius will be 100 pixels (the diameter 200 pixels). You're not actually getting the SIZE of the player character, just his SCALE. That's why I grabbed his dimensions via a ViewFrame pointer.

A ViewFrame contains information regarding a single frame in a view (hence the name). You can use a ViewFrame pointer to get the Graphic the frame represents which is the actual sprite slot assigned to the image within AGS. You can in turn use the ViewFrame.Graphic property to get the sprite's height/width using the Game.SpriteHeight/Game.SpriteWidth properties.

Finally once you have the height/width (in the previous example I wrote, whichever is the greater of the two), you can apply the Character's scale to that value which will give you the actual size (in pixels) of the Character when displayed on-screen (regardless of whether ManualScaling is enabled for the Character or not, the Character.Scaling property is always updated properly).

Hopefully I've explained my example well enough. And just to be clear, here is the example code again:

ViewFrame* frame = Game.GetViewFrame(player.View, player.Loop, player.Frame);
float fr = IntToFloat(Game.SpriteHeight[frame.Graphic]);
if (Game.SpriteWidth[frame.Graphic] > Game.SpriteHeight[frame.Graphic]) fr = IntToFloat(Game.SpriteWidth[frame.Graphic]);
fr *= (IntToFloat(player.Scaling) / 100.0) / 2.0;
// fr += 1.0;
Flashlight.Radius = fr;
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: LeChuck on Mon 19/11/2007 03:53:02
Does anyone know if you can get a gradually changing transparency using this module without resorting to 32-bit / png's with alpha channels? It wouldn't matter if it wasn't as smooth as using an alpha channeled png... I tried messing around with moving around huge objects / GUIs with different transparency simulating darkness, but it totally killed my new computer. My game's in 16-bit colour and I'd like to keep it that way for performanence reasons.
Title: Re: MODULE: Flashlight v2.0 BETA 2
Post by: monkey0506 on Mon 19/11/2007 04:24:27
Now let me see if I can remember how this was set up before (I actually began working on this again about a week ago)...

I believe that if you define the constant FLASHLIGHT_GUI like this in the Flashlight script header:

#define FLASHLIGHT_GUI gFlashlight

Where gFlashlight is the script o-name of the GUI you want to use for the flashlight which must have 5 controls.

You can then set the Flashlight.Transparency property to set the transparency:

Flashlight.Transparency = 50;

Edit: Just uploaded v2.0 Beta 3. You can still use the FLASHLIGHT_GUI constant or you can call the new Flashlight.SetGUIMode function (however the GUI no longer requires any controls) and then use the Flashlight.Transparency property to set the transparency of the 'darkened' areas of the screen.
Title: Re: MODULE: Flashlight v2.0 BETA 3 - Updated 21 Nov. 2007
Post by: beomoud on Sun 02/11/2008 20:09:41
The link for the module is broken. Where can we get it from?
Title: Re: MODULE: Flashlight v2.0 BETA 3 - Updated 21 Nov. 2007
Post by: Rulaman on Mon 05/01/2009 17:14:21
Is there any chance that someone has the new version? (Or maybe an older one; MODULE)
Title: Re: MODULE: Flashlight v2.0 BETA 3.x - Updated 21 Nov. 2007
Post by: monkey0506 on Mon 05/01/2009 18:35:28
Your wish is...well...I've uploaded a version of the module. It appears to be BETA 3 or close enough to it to be functional. Let me know of any bugs and I'll look into it though. ;)
Title: Re: MODULE: Flashlight v2.0 BETA 3.x - Updated 21 Nov. 2007
Post by: Rulaman on Tue 06/01/2009 12:12:18
The only bug i found is... I can't download it. ???

EDIT (17:14): Tried again and downloading...
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Fri 16/01/2009 07:06:10
Bumpdate!

I've finally decided to release a final version of this module! ;)

Just for those who didn't read the first post: This now requires AGS 3.1.2+!

Further features include the ability to set the beam sprite at the same time as changing modes (new optional parameter), change the color of the area surrounding the beam sprite (it can now be drawn in any color), and highly improved drawing methods.

Now that we have alpha channeled beam sprites with transparency (32-bit, GUI mode only), the plugin officially has no advantages over the module. w00t! :P
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Dualnames on Fri 16/01/2009 09:08:17
That's really great news. Really. Good job, man. Great to see those old modules getting updated..cool. Thanks again.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Fri 16/01/2009 17:33:41
Thanks Dual...but for the record the plugin might have an advantage...I've discovered a bug! :=

The included "flashlight.bmp" doesn't appear to work. I'm looking into that right now.

The issue with "flashlight.bmp" was related to this recently reported bug (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=36612.msg480680#msg480680). So it should work fine as long as you're using the D3D driver or you stick to only non-AA sprites.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Sat 21/02/2009 16:25:29
Where can I download this module from? The link isn't working (Hosting Account Suspended)...
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Sat 21/02/2009 17:32:19
Sorry I forget I have to log in to their forums to prevent my account being suspended. It should be working now, and I'll try to remember to upload a mirror later. ;)
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Sun 22/02/2009 17:06:43
Ok, I can download the rar file now, but it's only 14kb and the Winrar says it's broken... :(
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Sun 22/02/2009 18:34:08
Urgh...my host is being stupid. I'll upload the mirror...sorry.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Wed 25/02/2009 20:55:34
Ok, thanks! But, how can I download the mirror? ;)
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Fri 27/02/2009 08:02:03
Everything is stupid. I've got the mirror up finally. Sorry, just been busy.

http://monkey.05.06.googlepages.com/Flashlight_2_0.rar

Google's reliable.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Wed 04/03/2009 17:48:01
Thanks, it's working now!

But I have a question:
In one of my game I used Flashlight 1.1 and it looked like this:
(http://pilczstudios.around.hu/flashlight12.jpg)

Is it possible with the newest version to create such gradient effect?
If yes, then please tell me how!
I've tried to import alpha channel images, but it didn't work.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Wed 04/03/2009 19:44:03
1. Make sure you're running the latest version of AGS.
2. Make sure you're running the game at 32-bit.
3. Make sure you preserve the alpha channel when you import the sprite.
4. Make sure you're running the module in GUI mode.*

If you have any complications after that, could you post the script you're using?

*This can be done with either a macro (#define) in the module header or directly from the script using Flashlight.SetGUIMode (where gFlashlight is the script o-name of your GUI):

Macro:
// Flashlight.ash
#define FLASHLIGHT_GUI gFlashlight


Script Function:
// initialization script
// presumably in game_start, or just before you turn the effect on
Flashlight.SetGUIMode(gFlashlight);
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Wed 04/03/2009 21:05:52
Ok, I found the error. I just forget to put the true in the create dynamic sprite line:
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(167, true);
It's working perfectly now, thank you!
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Thu 30/07/2009 17:57:13
It's me again ;)
I have a problem using the module.
My script is:
...
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(168, true);
Flashlight.SetGUIMode(gFlashlight, sprite);
Flashlight.Enabled = true;
Flashlight.Radius=0.0;
Flashlight.Transparency=2;
player.Say("I've turned the light off.");

But what is happening: the player talks then the flashlight turns off.
How can I make it in reverse order, like in the script?
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Fri 31/07/2009 05:03:46
Just so you know the Flashlight module does assume that you're always going to have some sort of "beam" area while the effect is turned on so setting Flashlight.Radius = 0.0 may not work as you might think.

It will actually in that case be defaulted to 0.5 which of course gives a 1 pixel diameter for the beam.

That's not the problem however. The real problem is with the fact that the module doesn't get a chance to update before you call the Say function. Try doing this:

// ...
import void Update(this FlashlightType*); // copy this line EXACTLY
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(168, true);
Flashlight.SetGUIMode(gFlashlight, sprite);
Flashlight.Enabled = true;
Flashlight.Radius=0.0;
Flashlight.Transparency=2;
Flashlight.Update(); // copy this line EXACTLY
player.Say("I've turned the light off.");


That will force the screen to update the flashlight effect prior to the player.Say command.

If it still doesn't work you can instead just add a Wait(1); right before calling player.Say. I'm not certain whether the GUI would actually get the chance to update on-screen even with directly calling the internal update function.

I'll do more testing on this myself to see. If it does get to update in time it might be prudent to import the updating function as part of the primary structure anyway.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Fri 31/07/2009 16:48:26
Hello there! Look I just wondering if you have any tutorial to undertand how start with this excelent Module!

Thanks for your time!

Nahuel.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Joseph DiPerla on Fri 31/07/2009 22:03:00
You should only post in one spot. Here is a manual for the module: http://americangirlscouts.org/agswiki/Flashlight
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Fri 31/07/2009 23:59:22
Thanks for linking that for me Joseph. However although the information included should still be valid, there's admittedly not really any example code to work with.

In order to use this module you should have a basic grasp on scripting in AGS. If not, check out the scripting tutorial in the AGS manual first.

Next you need to decide a few things about how you want to use the module. You can change your mind later, but you'll need someplace to start at. If you want a basic effect, don't care too much about "jaggy" edges in your sprites, and/or are running at 8-bit then using Overlay mode is the simplest route for you. If however you want smoothed edges around the "beam" area, or perhaps want the darkened areas to be partially transparent, or any sort of alpha channeled sprites whatsoever you will want to use GUI mode instead. The difference is the way that the module actually displays the effect, both of which have significant pros and cons.

Depending which mode you choose, you will need to call either Flashlight.SetGUIMode or Flashlight.SetOverlayMode. Both of these can optionally accept a parameter to specify a new "beam" sprite, but we'll come back to that in a moment. If you have chosen GUI mode you will need to have a GUI set up, dedicated to being used by this module. The actual size/location of the GUI doesn't matter, but it should not have any controls whatsoever. You will need to pass this GUI's script name as the first parameter when you call SetGUIMode.

As far as the "beam" sprite I referenced before, basically the module handles filling in the entire screen with the darkened area. You however, must supply a DynamicSprite* to a valid sprite for the area that will not be darkened. This area will be the "beam" of your flashlight.

There are two example sprites included which you can feel free to use, or you can create your own. The sprites are "flashlight.bmp" and "import_only.png". "flashlight.bmp" is designed with Overlay mode in mind (though it works fine with GUI mode as well) and gives a sort of simple, low-res sort of beam effect. "import_only.png" is designed for GUI mode only and has an alpha channel which gives it nice, smoothed edges around the beam.

If you want to use "flashlight.bmp" you can either A) just include it with the EXE file in your distribution (put it in your "Compiled" folder) or B) actually import the sprite. If the module detects the file in the same folder as the EXE when the game is run then it will automatically be loaded for the beam sprite. If you import it into AGS you will have to manually set the sprite (see next paragraph).

If you want to use "import_only.png" you must import it into AGS's sprite manager. Unless you intentionally want to destroy the alpha channel, you should also choose to preserve that on import. Once the sprite is imported then you will have to manually load the beam sprite for the module using the Flashlight.SetBeamSprite function, or just by passing a DynamicSprite* to the sprite when you set the mode.

The final important setup point is setting the Flashlight.Radius property. This will set the radius (half the diameter) (in pixels) you want the beam of your flashlight to be drawn at. This is a float property, however note that if it rounds to 0 or less then it will default to a radius of 0.5. So for example a radius of 5.0 would make the beam appear 10 pixels across.

Finally, you use Flashlight.Enabled to turn the effect on/off.

Okay, so that's the most important steps to getting the module's effects up and running. The last thing of course is "where do I put these?" so let me cover that as well. You can change any of these settings at any time, however you're going to need to set them all before you can utilize the effect. Therefore, putting them in the game_start function (in GlobalScript.asc) is a good place to initialize your settings:

// game_start - using GUI mode with import_only.png imported as sprite 42
DynamicSprite *sprite = DynamicSprite.CreateFromExistingSprite(42);
Flashlight.SetGUIMode(gFlashlight, sprite);
Flashlight.Radius = 5.0;

// on_key_press
if (keycode == eKeyTab) Flashlight.Enabled = !Flashlight.Enabled;
// the above is shorthand for "Flashlight.Enabled = (Flashlight.Enabled == false);"
// which of course would toggle the status of Flashlight.Enabled


Anything else should be covered by reading the documentation. I hope I've been thorough enough. If you have any other questions feel free to ask.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: placyd on Sat 01/08/2009 16:10:30
Quote from: monkey_05_06 on Fri 31/07/2009 05:03:46

// ...
import void Update(this FlashlightType*); // copy this line EXACTLY
DynamicSprite* sprite = DynamicSprite.CreateFromExistingSprite(168, true);
Flashlight.SetGUIMode(gFlashlight, sprite);
Flashlight.Enabled = true;
Flashlight.Radius=0.0;
Flashlight.Transparency=2;
Flashlight.Update(); // copy this line EXACTLY
player.Say("I've turned the light off.");


Thanks, monkey! This update thing is working well!  :D
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Sat 01/08/2009 22:45:14
Monkey Thank you very much for the explaination. This is realy realy good. i appreciate your time.

If I have any question when I try I'll ask in this post.

Thankyou again.

Nahuel. From Argentina.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Sun 02/08/2009 01:01:03
You're both very welcome.

Given that Flashlight.Update worked for you placyd I shall make a point (at some point) to import the function as part of the module. Normally you shouldn't need to call it, but as your case demonstrates for example, if you need the effect to be drawn after making some changes but prior to the next game loop being run (for example calling a blocking function, like Character.Say) then it's vital to getting it to update in time. ;) If you need to use Flashlight.Update in other scripts, just move the import line into the Flashlight.ash file.

Nahuel definitely this is the place to ask if you have any further questions. I'll try to be prompt if able. I tried to be thorough enough to get you started though, so hopefully you'll be good to go from here!
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Sun 02/08/2009 04:29:15
Quote from: monkey_05_06 on Sun 02/08/2009 01:01:03
You're both very welcome.

Given that Flashlight.Update worked for you placyd I shall make a point (at some point) to import the function as part of the module. Normally you shouldn't need to call it, but as your case demonstrates for example, if you need the effect to be drawn after making some changes but prior to the next game loop being run (for example calling a blocking function, like Character.Say) then it's vital to getting it to update in time. ;) If you need to use Flashlight.Update in other scripts, just move the import line into the Flashlight.ash file.

Nahuel definitely this is the place to ask if you have any further questions. I'll try to be prompt if able. I tried to be thorough enough to get you started though, so hopefully you'll be good to go from here!

Monkey, I have a question. How can I start in a darkroom?

Thank you.

Nahuel.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Sun 02/08/2009 04:53:50
If you want the first room to have the effect enabled you can set "Flashlight.Enabled = true;" in that room's "Player enters room (before fade-in)" event.

However the module does expect to have some area shown so if you wanted, for example, the entire room to be dark until the player turns the flashlight on (by using an inventory item for example) then you would need to darken the screen a different way. You could use FadeOut. If you call "FadeOut(64);" that would make sure the screen stays black and then when the player activates the flashlight you could call "FadeIn(64);" (after turning the flashlight on).
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Sun 02/08/2009 05:29:25
Excelent, tanks for help me!!  :=

Thank you very much Monkey.

Nahuel.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Mon 03/08/2009 14:45:52
Monkey, I have a problem. My room doesn't stay dark with FadeOut(64), FadeOut(100),  FadeOut(1).
Another way to dark the background??

Thank you.

Nahuel.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Tue 04/08/2009 19:56:24
The maximum value for FadeOut is 64 which should be instantaneous. I probably should have said to put the FadeOut call in "(after fade-in)" obviously otherwise the editor is going to try and fade it back in. I just wasn't thinking. Sorry about that.

I haven't actually tested FadeOut in the after fade-in function, but it should work fine with FadeOut(64). That should also answer your other question.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Nahuel on Tue 04/08/2009 20:10:26
Thank you very much monkey!!

Nahuel.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Dave Gilbert on Fri 25/06/2010 18:21:10
Hi all.  Bit of an old thread, but I've been tinkering around with this module and I am having some issues.  I am using AGS 3.2v5, so I *think* it is probably related to the alpha channel/GUI problem that was brought up in this thread (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=37668.msg545559#msg545559), but I wanted to confirm it before I took it further.

In a nutshell, here's my room with the flashlight off:

(http://www.davelgil.com/flash_off.PNG)

And with it on:

(http://www.davelgil.com/flash_on.PNG)

Displaying it in overlay mode works perfectly.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Adrian on Thu 01/07/2010 10:22:39
Have you tried setting the GUI's background colour to 0 in the panel?
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Dave Gilbert on Thu 01/07/2010 22:22:45
Adrian: Yes, it is definitely set to 0.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Aarduil on Thu 06/10/2011 22:15:01
I am just getting started with AGS, but this script provides a very evocative feature that I want to have in my project from the start!

I, uh, implemented it somewhat. But I'm definitely getting something wrong, because it looks like this:
http://i.imgur.com/l9Noo.png

I would appreciate any tips!
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Thu 06/10/2011 22:19:36
Hi Aarduil,

Could you upload the image you're using as the beam sprite? I think I might know what your issue is there, but I'm not entirely sure just from that image.

Also, dunno why I never got around to answering Dave's question. If anyone else experiences the same problem, if I don't respond please feel free to PM me a reminder. ;)

Edit: Just to be sure that this is still functional with the latest version(s) of AGS, I've tested it in a beta version of 3.2.2, and it seemed to be working fine for me. If you imported the file "import_only.png", make sure you don't select to use the "Top-left pixel" (or any of the other corners) as the transparent area of the image. Change that drop-box to "No transparency" or "Leave as-is". Also make sure your game is 32-bit and you select "Yes" to use the alpha channel if you want to use that image.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Aarduil on Fri 07/10/2011 07:44:35
Quote from: monkey_05_06 on Thu 06/10/2011 22:19:36
If you imported the file "import_only.png", make sure you don't select to use the "Top-left pixel" (or any of the other corners) as the transparent area of the image. Change that drop-box to "No transparency" or "Leave as-is".

Was exactly that. It works perfectly now, thanks!
http://i.imgur.com/g4FUZ.png
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Akril15 on Tue 15/05/2012 19:58:03
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). (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=14436.msg176064#msg176064) 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!
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 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:
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Akril15 on Wed 16/05/2012 05:15:51
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);
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Khris on Wed 16/05/2012 17:38:22
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.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 on Wed 16/05/2012 17:40:55
Well just to confirm, this is the code that's generating the actual effect:

Code (ags) Select

  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?
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Khris on Wed 16/05/2012 18:09:58
I'm sure that's what Akril was saying.
I did a quick test using this sprite:
(http://i.imgur.com/qc9Ep.png)

I put it in a new view/character and used:
Code (ags) Select
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.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Akril15 on Fri 18/05/2012 05:41:13
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!
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: monkey0506 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
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Khris on Fri 18/05/2012 13:42:17
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. :)
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Akril15 on Fri 18/05/2012 20:24:59
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.
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: Voedino on Mon 05/10/2020 09:06:42
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
Title: Re: MODULE: Flashlight v2.0 [FINAL] - Updated 16 January 2009!
Post by: morganw on Mon 05/10/2020 09:56:06
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.