Time for action – the Game1 Update method

  1. Replace the current Update() method in the Game1 class with the following:
    protected override void Update(GameTime gameTime)
    {
        Camera.Position = new Vector2(hscroll.Value, vscroll.Value);
    
        MouseState ms = Mouse.GetState();
    
        if ((ms.X > 0) && (ms.Y > 0) &&
            (ms.X < Camera.ViewPortWidth) &&
            (ms.Y < Camera.ViewPortHeight))
        {
            Vector2 mouseLoc = Camera.ScreenToWorld(
                new Vector2(ms.X, ms.Y));
     if (Camera.WorldRectangle.Contains( (int)mouseLoc.X, (int)mouseLoc.Y)) { if (ms.LeftButton == ButtonState.Pressed) { TileMap.SetTileAtCell( TileMap.GetCellByPixelX((int)mouseLoc.X), TileMap.GetCellByPixelY((int)mouseLoc.Y), DrawLayer, DrawTile); } if ((ms.RightButton == ButtonState.Pressed) && (lastMouseState.RightButton ...

Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.