ジェットストリーム
■残像?
残像って?と聞かれたので、何種類か実験で作成してみました、このサンプルは、1つのパーティクルに対して「particleCount 」で指定した分残像の座標を保持して残像部分を表現する方法です。
■ソース
Game1.cs
namespace WindowsGame { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; SpriteBatch sprite; Texture2D texture; const int particleCount = 20; Particle particle; public Game1() { graphics = new GraphicsDeviceManager(this); content = new ContentManager(Services); } protected override void Initialize() { Random ran = new Random(); particle = new Particle( (float)ran.Next(700), (float)ran.Next(500), (float)ran.Next(360) * 3.14159f / 180.0f, particleCount); base.Initialize(); } protected override void LoadGraphicsContent(bool loadAllContent) { if (loadAllContent) { sprite = new SpriteBatch(graphics.GraphicsDevice); texture = content.Load<Texture2D>("ball"); } } protected override void Update(GameTime gameTime) { particle.Move(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); sprite.Begin(SpriteBlendMode.Additive); byte c; for (int i = 0; i < particleCount; i++) { c = (byte)(255 / (i + 1)); sprite.Draw(texture, particle.Pos[i], new Color(c, c, c, 255)); } sprite.End(); base.Draw(gameTime); } } }
Particle.cs
using System; using System.Collections.Generic; using System.Text; using Microsoft.Xna.Framework; namespace WindowsGame { class Particle { public int countMax; public Vector2[] Pos; public Vector2 Direction; public Particle(float x, float y, float ang, int count) { countMax = count; Pos = new Vector2[ countMax]; Pos[ 0 ] = new Vector2(x, y); Direction = new Vector2((float)Math.Sin(ang) * 10.0f, (float)Math.Cos(ang) * 10.0f); //同じ座標にコピー for (int i = 1; i < countMax; i++) Pos[i] = Pos[i - 1]; } public void Move() { Pos[ 0 ] += Direction; if ((Pos[ 0 ].X < 0) || (Pos[ 0 ].X > 800 - 64)) Direction.X = -Direction.X; if ((Pos[ 0 ].Y < 0) || (Pos[ 0 ].Y > 600 - 64)) Direction.Y = -Direction.Y; //座標をずらそう for (int i = countMax-1; i > 0; i--) Pos[ i ] = Pos[ i - 1 ]; } } }