Beams are used internally for rendering cords, such as Gello's umbilical cord. Note that this only handles rendering and not physics.
Beams are best demonstrated by looking at the Ball and Chain enemies found in Gehenna, which have a chain that dynamically moves and stretches depending on how far away the spiked ball is from where it is chained.
localmod=RegisterMod("Repentogon Beam Example",1)-- Some constants.localDAMAGE_MULTIPLIER=0.01localITEM_ID=Isaac.GetItemIdByName("Life-Drain Gem")-- First make a sprite.localsprite=Sprite()sprite:Load("gfx/chain_beam.anm2",true)sprite:Play("Idle",true)-- Handles the beam and damaging of the closest enemy to the player.functionmod:HandleLifeSteam(player)localdata=player:GetData()-- Check if the player has our item, first.ifnotplayer:HasCollectible(ITEM_ID)thenreturnend-- Get the beam stored in player:GetData(), or create one if it doesn't exist.localbeam=data.LifeStealBeamifnotbeamthen-- Create the beam. We don't need to use the overlay here.data.LifeStealBeam=Beam(sprite,"chain",false,false)beam=data.LifeStealBeamend-- Get the closest enemylocalclosestDistance,closestEnemyfor_,enemyinipairs(Isaac.GetRoomEntities())doifenemy:IsActiveEnemy()andenemy:IsVulnerableEnemy()thenlocaldistanceToPlayer=enemy.Position:Distance(player.Position)ifnotclosestDistanceorclosestDistance>distanceToPlayerthenclosestEnemy=enemy:ToNPC()closestDistance=distanceToPlayerendendend-- If there's no enemy in the room, end the function early.ifnotclosestEnemythenreturnend-- Deal damage every frame.closestEnemy:TakeDamage(player.Damage*DAMAGE_MULTIPLIER,0,EntityRef(player),0)-- Render the beam. The position is in screen coordinates.-- The second argument, SpritesheetCoordinate, is what the Y position of the spritesheet is by the time this Point is reached.-- So for example, two points of 0 and 64 SpritesheetCoordinate will render the sprite starting from y0 to 64.-- An additional Point with a SpritesheetCoordinate of 0 will draw it in reverse from y64 to y0.-- Width is an optional third argument that is a multiplier used to determine the width of the Beam.beam:Add(Isaac.WorldToScreen(player.Position),0)beam:Add(Isaac.WorldToScreen(closestEnemy.Position),64)-- 64 is the height of the spritesheet.-- Render the beam. By default, this will clear all points.beam:Render()endmod:AddCallback(ModCallbacks.MC_POST_PLAYER_RENDER,mod.HandleLifeSteam)