Skip to main content

WeaponEntityFactory

WeaponEntityFactory creates a weapon entity and links it to an existing player entity via OwnerComponent.

Usage

WeaponEntityFactory(ownedBy: playerEntity, scale: scale).make(in: world)

// With explicit offset and texture
WeaponEntityFactory(
ownedBy: playerEntity,
textureName: "handgun",
offset: SIMD2(10, -5),
scale: scale,
lastFiredAt: 0
).make(in: world)

Parameters

ParameterTypeDefaultDescription
playerEntityThe player entity this weapon belongs to
textureNameString"handgun"Asset catalog name for the weapon sprite
offsetSIMD2<Float>.zeroPosition offset relative to the player
scaleFloat1World scale
lastFiredAtFloat0Timestamp of the last shot (used to restore cooldown state)

Components Added

ComponentInitial Value
TransformComponentPlayer position + offset, rotation 0, scale
FacingComponentCopied from the player's current facing
SpriteComponenttextureName, layer .weapon
OwnerComponentownerEntity: player, offset
WeaponComponentType .handgun, mana cost 10, attack speed 1, cooldown 0.2s, lastFiredAt