1.

Solve : Draw multiple of the same sprite without ton's of strings -- XNA --?

Answer»

How would I use a "for" (or other) loop to draw a bullet sprite in a unique direction from the center point?

--Liam

P.S. Where the PROGRAM checks if the spacebar is pressed is where a new bullet will be created.

Code:
Code: [Select]using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace SupaShota
{
public class Game1 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Vector2 v = new Vector2(350, 250);//base point
Texture2D bar;//BARREL
Texture2D b;//base
Texture2D bul;//bullet

public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
base.Initialize();
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
b = Content.Load<Texture2D>("base");
bar = Content.Load<Texture2D>("barrel");
bul = Content.Load<Texture2D>("bullet");
// TODO: use this.Content to load your game content here
}

MouseState MS;
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
this.Exit();

MS = Mouse.GetState();
KeyboardState ks = Keyboard.GetState();
if (ks.IsKeyDown(Keys.Space))
{

}

base.Update(gameTime);
}

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
spriteBatch.Draw(b, v, Color.White);
double an = Math.Atan2(MS.Y - v.Y, MS.X - v.X);
Rectangle r = new Rectangle((int)v.X + 50, (int)v.Y + 50, bar.Width, bar.Height);
spriteBatch.Draw(bar, r, NULL, Color.White, (FLOAT)an, Vector2.Zero, SpriteEffects.None, 0);
/*
*
* Here is where the "for" statement or such will go.
*
*
*/
spriteBatch.End();
base.Draw(gameTime);
}
}
}

Please tell me if I forgot to mention something.



Discussion

No Comment Found