Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FlameParticle.cs
Go to the documentation of this file.
5
7
9{
10 public float FadeOutNormalizedTime = 1f;
11
12 private float _timeTolive;
13
14 private float _timeSinceSpawn;
15
17
18 private int _packedShaderIndex;
19
20 public override void FetchFromPool()
21 {
22 base.FetchFromPool();
24 _timeTolive = 0f;
25 _timeSinceSpawn = 0f;
28 }
29
30 public override void SetBasicInfo(Asset<Texture2D> textureAsset, Rectangle? frame, Vector2 initialVelocity, Vector2 initialLocalPosition)
31 {
32 base.SetBasicInfo(textureAsset, frame, initialVelocity, initialLocalPosition);
33 _origin = new Vector2(_frame.Width / 2, _frame.Height - 2);
34 }
35
36 public void SetTypeInfo(float timeToLive, int indexOfPlayerWhoSpawnedIt, int packedShaderIndex)
37 {
38 _timeTolive = timeToLive;
39 _indexOfPlayerWhoSpawnedThis = indexOfPlayerWhoSpawnedIt;
40 _packedShaderIndex = packedShaderIndex;
41 }
42
43 public override void Update(ref ParticleRendererSettings settings)
44 {
45 base.Update(ref settings);
46 _timeSinceSpawn += 1f;
48 {
49 base.ShouldBeRemovedFromRenderer = true;
50 }
51 }
52
53 public override void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
54 {
55 Color color = new Color(120, 120, 120, 60) * Utils.GetLerpValue(1f, FadeOutNormalizedTime, _timeSinceSpawn / _timeTolive, clamped: true);
56 Vector2 vector = settings.AnchorPosition + LocalPosition;
57 ulong seed = Main.TileFrameSeed ^ (((ulong)LocalPosition.X << 32) | (uint)LocalPosition.Y);
59 for (int i = 0; i < 4; i++)
60 {
61 DrawData drawData = new DrawData(position: vector + new Vector2(Utils.RandomInt(ref seed, -2, 3), Utils.RandomInt(ref seed, -2, 3)) * Scale, texture: _texture.Value, sourceRect: _frame, color: color, rotation: Rotation, origin: _origin, scale: Scale, effect: SpriteEffects.None);
62 drawData.shader = _packedShaderIndex;
63 DrawData cdd = drawData;
64 PlayerDrawHelper.SetShaderForData(player, 0, ref cdd);
65 cdd.Draw(spritebatch);
66 }
67 Main.pixelShader.CurrentTechnique.Passes[0].Apply();
68 }
69}
static void SetShaderForData(Player player, int cHead, ref DrawData cdd)
override void Update(ref ParticleRendererSettings settings)
override void SetBasicInfo(Asset< Texture2D > textureAsset, Rectangle? frame, Vector2 initialVelocity, Vector2 initialLocalPosition)
override void Draw(ref ParticleRendererSettings settings, SpriteBatch spritebatch)
void SetTypeInfo(float timeToLive, int indexOfPlayerWhoSpawnedIt, int packedShaderIndex)
static Effect pixelShader
Definition Main.cs:2764
static Player[] player
Definition Main.cs:1803
static int RandomInt(ref ulong seed, int max)
Definition Utils.cs:1648
static float GetLerpValue(float from, float to, float t, bool clamped=false)
Definition Utils.cs:203
void Draw(SpriteBatch sb)
Definition DrawData.cs:146