SpriteBatchでもαブレンディング(Zune編)
以前作った、SpriteBatchでもαブレンディング(色加算限定)http://d.hatena.ne.jp/sanoh/20070525をZuneに移植してみました
しかし、Zuneで動かす前にまずPCで開発。
namespace WindowsGame4 { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch sprite; Texture2D texture; const int particleMax = 48; Particle[] particle = new Particle[particleMax]; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; graphics.PreferredBackBufferWidth = 240; graphics.PreferredBackBufferHeight = 320; TargetElapsedTime = TimeSpan.FromSeconds(1 / 30.0); } protected override void Initialize() { Random ran = new Random(); for (int i = 0; i < particleMax; i++) particle[i] = new Particle( (float)ran.Next(100), (float)ran.Next(200), (float)ran.Next(360) * 3.14159f / 180.0f); base.Initialize(); } protected override void LoadContent() { sprite = new SpriteBatch(GraphicsDevice); texture = Content.Load<Texture2D>("ball"); } protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) this.Exit(); foreach (Particle p in particle) p.Move(); base.Update(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.Black); sprite.Begin(SpriteBlendMode.Additive); foreach (Particle p in particle) sprite.Draw(texture, p.Pos, Color.White); sprite.End(); base.Draw(gameTime); } } }
Zuneの画面サイズは240X320(QVGA)なので
graphics.PreferredBackBufferWidth = 240;
graphics.PreferredBackBufferHeight = 320;
と設定して画面サイズを調整します、あとはそのまま書けばOK
Zineは描画スピードがそんなによくないので、パーティクルの数を48個に
const int particleMax = 48;
Partivole.csは
public void Move() { Pos += Direction; if ((Pos.X < 0) || (Pos.X > 240-64)) Direction.X = -Direction.X; if ((Pos.Y < 0) || (Pos.Y > 320-64)) Direction.Y = -Direction.Y; }