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

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

Previous topic - Next topic

Da_Elf

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.
Code: ags
#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

monkey0506

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:

Code: ags
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;

LeChuck

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.

monkey0506

#43
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:

Code: ags
#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:

Code: ags
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.

beomoud

The link for the module is broken. Where can we get it from?

Rulaman

Is there any chance that someone has the new version? (Or maybe an older one; MODULE)
Zak: Komm mit mir Sushi.
Zak: Come with me Sushi.

monkey0506

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. ;)

Rulaman

The only bug i found is... I can't download it. ???

EDIT (17:14): Tried again and downloading...
Zak: Komm mit mir Sushi.
Zak: Come with me Sushi.

monkey0506

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

Dualnames

That's really great news. Really. Good job, man. Great to see those old modules getting updated..cool. Thanks again.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

monkey0506

#50
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. So it should work fine as long as you're using the D3D driver or you stick to only non-AA sprites.

placyd

Where can I download this module from? The link isn't working (Hosting Account Suspended)...

monkey0506

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. ;)

placyd

Ok, I can download the rar file now, but it's only 14kb and the Winrar says it's broken... :(

monkey0506

Urgh...my host is being stupid. I'll upload the mirror...sorry.

placyd


monkey0506

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.

placyd

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:


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.

monkey0506

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:
Code: ags
// Flashlight.ash
#define FLASHLIGHT_GUI gFlashlight


Script Function:
Code: ags
// initialization script
// presumably in game_start, or just before you turn the effect on
Flashlight.SetGUIMode(gFlashlight);

placyd

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!

SMF spam blocked by CleanTalk