public void Draw( SpriteBatch spriteBatch, GraphicsDeviceManager graphics, Texture2D ball, BallSimulation bs) { float scale = camera.getScale(bs.ballRadius(), ball.Bounds.Width); spriteBatch.Begin(); spriteBatch.Draw(ball, camera.modelToViewCoords(bs.position()), ball.Bounds, Color.White, 0, new Vector2(ball.Bounds.Width / 2, ball.Bounds.Height / 2), scale, SpriteEffects.None, 0); spriteBatch.End(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); ballSimulation = new BallSimulation(); ballVIew = new BallView(graphics, ballSimulation, Content); // TODO: use this.Content to load your game content here //camera = new Camera(GraphicsDevice.Viewport); }
/// en konstruktor som laddar in först i klassen! public BallView(GraphicsDeviceManager graphics, BallSimulation BallSimulation, ContentManager Content) { ball = Content.Load<Texture2D>("master_ball");///laddar in bollen //detta görs bara en gång! box = new Texture2D(graphics.GraphicsDevice, 1, 1);///denna skapar en box box.SetData<Color>(new Color[] { Color.Black });/// denna sätter vilken färg! camera = new Camera(graphics.GraphicsDevice.Viewport);/// skapar en ny camera instans ballSimulation = BallSimulation; }
//http://stackoverflow.com/questions/5751732/draw-rectangle-in-xna-using-spritebatch protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); ball = Content.Load<Texture2D>("ball"); gameArea = new Texture2D(GraphicsDevice, 1, 1); gameArea.SetData(new[] { Color.Yellow }); bv = new BallView(GraphicsDevice.Viewport); bs = new BallSimulation(); // TODO: use this.Content to load your game content here }