Classes:SpotLight
Note: Wait! Stop! You do not need to copy this actor's code into your project! Here's why:
|
Spotlight | |||
---|---|---|---|
Actor type | Internal | Game | ![]() |
DoomEd Number | 9840 | Class Name | SpotLight |
Classes: DynamicLight→SpotLight
→SpotLightAdditive
→SpotLightSubtractive
→SpotLightAttenuated
→SpotLightPulse
→SpotLightPulseAdditive
→SpotLightPulseSubtractive
→SpotLightPulseAttenuated
→SpotLightFlicker
→SpotLightFlickerAdditive
→SpotLightFlickerSubtractive
→SpotLightFlickerAttenuated
→SectorSpotLight
→SectorSpotLightAdditive
→SectorSpotLightSubtractive
→SectorSpotLightAttenuated
→SpotLightFlickerRandom
→SpotLightFlickerRandomAdditive
→SpotLightFlickerRandomSubtractive
→SpotLightFlickerRandomAttenuated
A spotlight is a version of dynamic light that has a cone shape instead of being simply spherical. Modifying its inner and outer angles allows changing both the area of the light and how soft/hard its edge is.
This class doesn't define any unique properties, flags or fields; they are all contained in the DynamicLight class.
Variations
SpotLight has a number of subclasses with different behaviors and lighting modes:
Class name | DoomEdNum | Description |
---|---|---|
SpotLight | 9840 | Basic |
SpotLightPulse | 9841 | Pulsing |
SpotLightFlicker | 9842 | Flickering |
SectorSpotLight | 9843 | Sector (depends on sector brightness) |
SpotLightFlickerRandom | 9844 | Randomly flickering |
SpotLightAdditive | 9850 | Additive |
SpotLightPulseAdditive | 9851 | Additive pulsing |
SpotLightFlickerAdditive | 9852 | Additive flickering |
SectorSpotLightAdditive | 9853 | Sector additive |
SpotLightFlickerRandomAdditive | 9854 | Sector randomly flickering additive |
SpotLightSubtractive | 9860 | Subtractive |
SpotLightPulseSubtractive | 9861 | Pulsing subtractive |
SpotLightFlickerSubtractive | 9862 | Flickering subtractive |
SectorSpotLightSubtractive | 9863 | Sector subtractive |
SpotLightFlickerRandomSubtractive | 9864 | Randomly flickering subtractive |
SpotLightAttenuated | 9870 | Attenuated |
SpotLightPulseAttenuated | 9871 | Pulsing attenuated |
SpotLightFlickerAttenuated | 9872 | Flickering attenuated |
SectorSpotLightAttenuated | 9873 | Sector attenuated |
SpotLightFlickerRandomAttenuated | 9874 | Randomly flickering attenuated |
Examples
This shows an example weapon that acts as a flashlight by spawning a Spotlight and modifying its values directly to move it:
class SimpleFlashlight : Weapon
{
Spotlight beam; //pointer to the spawned spotlight
// Simple wrapper for A_WeaponReady. This makes sure
// that Fire state cannot be called repeatedbly by
// holding the attack button, so we don't cycle the
// flashlight on/off too quickly:
action void A_FlashlightReady()
{
int fflags = 0;
// Check if player was holding fire button during last tic;
// if so, disable the ability to fire:
if (player.oldbuttons & BT_ATTACK)
{
fflags |= WRF_NOPRIMARY;
}
A_WeaponReady(fflags);
}
// Dedicated function that spawns/despawns the light:
action void A_ToggleFlashlight()
{
// If light already exists, destroy it:
if (invoker.beam)
{
invoker.beam.Destroy();
}
// Otherwise spawn it:
else
{
// Spawn the light and pass values to it:
invoker.beam = Spotlight(Spawn('Spotlight', (pos.xy, player.viewz - 10)));
invoker.beam.args[0] = 255; //red
invoker.beam.args[1] = 255; //green
invoker.beam.args[2] = 255; //blue
invoker.beam.args[3] = 320; //length of the spotllight
invoker.beam.SpotInnerAngle = 10; //inner angle (brightest area)
invoker.beam.SpotOuterAngle = 30; //outerangle (dimmer area)
invoker.beam.bATTENUATE = true; //makes it attenuated (will interact with materials)
}
A_StartSound("switches/normbutn", CHAN_WEAPON); //flashlight sound
}
override void DoEffect()
{
Super.DoEffect();
// If there's no valid owner, or the owner switched to a different weapon
// but the light still exists, remove it:
if (!owner || !owner.player || !owner.player.readyweapon || owner.player.readyweapon != self)
{
if (beam)
{
beam.Destroy();
}
return;
}
// Otherwise keep adjusting the light's angle, pitch and position
// so it's right below the player's view:
if (beam)
{
beam.SetOrigin((owner.pos.xy, owner.player.viewz - 10), true);
beam.A_SetAngle(owner.angle, SPF_INTERPOLATE);
beam.A_SetPitch(owner.pitch, SPF_INTERPOLATE);
}
}
// This uses Fist sprites for simplicity:
States {
Ready:
PUNG A 1 A_FlashlightReady();
loop;
Fire:
PUNG A 10 A_ToggleFlashlight();
goto Ready;
Select:
PUNG A 1 A_Raise;
loop;
Deselect:
PUNG A 1 A_Lower;
loop;
}
}
(Example from ZScript Examples by Agent_Ash)
ZScript definition
ZScript definitions for spot lights are very simple and can be found on GZDoom github and in gzdoom.pk3 under zscript/actors/shared/dynlights.zs.