Protected_Backing storage for the rect getter. Subclasses can read it; mutate via pos/rebuildRotation instead of touching it directly.
ProtectedimageCurrent pre-rotated sprite. Re-baked by rebuildRotation from the un-rotated originalImage.
ProtectedlifetimeAccumulated time (seconds). Drives the alive check against maxLifetime.
Seconds after which alive flips to false. Defaults to Infinity — no natural expiry.
OptionalpayloadCaller-supplied data. Typed via the class generic so consumers can read projectile.payload without casting.
ProtectedposTop-left position. Cloned from the constructor arg so the caller's Vec2 isn't aliased.
ProtectedrotationCurrent sprite rotation in radians, kept in sync with vel by rebuildRotation.
Magnitude multiplier applied to vel each update: pos += vel * speed * dt. Pass a unit-length vel to make this read as "pixels per second".
ProtectedvelVelocity direction vector. Multiplied by speed each update — pass a unit vector for speed-as-px-per-second semantics. Cloned from the constructor arg.
false once lifetime reaches maxLifetime. Owners typically filter dead projectiles out of their list each frame.
Read-only AABB tracking pos and the (rotated) image size. Recomputed in update and rebuildRotation.
Blit the pre-rotated image at pos + offset. offset is useful for shifting by a camera/world transform without mutating pos.
Re-bake the sprite to match the current vel direction (rotation = atan2(vel.y, vel.x)) and update rect to the new bounds. Allocates a fresh rotated canvas every call — no internal cache, so heavy re-aiming (homing/seeking) is a candidate for adding quantized caching.
Force alive to false immediately (sets lifetime past maxLifetime). Use when the projectile should die on collision/impact, not from natural expiry.
Integrate motion and advance lifetime. Doesn't re-bake the rotation — call rebuildRotation after mutating vel.
A self-propelled sprite —
update(dt)advancesposalongvel * speed, accumulateslifetime, and flips alive tofalseoncelifetime >= maxLifetime. The image is pre-baked to a rotated canvas matching the velocity direction; call rebuildRotation after re-aiming.The
Tgeneric types the optional payload so callers can attach typed metadata (damage, owner, etc.) without losing inference.