public void Draw(SpriteBatch sb, Camera gameCamera) { /// CAMERA STUFF: A lot has changed here! // Need to use SamplerState.PointClamp to avoid tile artifacting with floating point positioning. Try setting it to null to see the difference! sb.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp, null, null); for (int y = 0; y < MAP_HEIGHT; y++) { for (int x = 0; x < MAP_WIDTH; x++) { // We don't want to draw a blank tile (saves triangles!) if (Tiles[x, y] == 0) continue; // First calculate the position we want to draw the tile at Vector2 tilePos = new Vector2(x * TILE_WIDTH, y * TILE_HEIGHT); // Next, check if that position is inside the camera's visible area // We subtract from left/top to allow for tiles to be drawn helf-off the screen if (tilePos.X >= gameCamera.VisibleArea.Left - Map.TILE_WIDTH && tilePos.Y >= gameCamera.VisibleArea.Top - Map.TILE_HEIGHT && tilePos.X <= gameCamera.VisibleArea.Right && tilePos.Y <= gameCamera.VisibleArea.Bottom) { sb.Draw(tilesTex, // Subtract camera position from draw position tilePos - gameCamera.Position, new Rectangle(Tiles[x, y] * TILE_WIDTH, 0, TILE_WIDTH, TILE_HEIGHT), Color.White); } } } sb.End(); }
public void Draw(SpriteBatch sb, Camera gameCamera) { // Start/end drawing at Manager level so all enemies are drawn in one batch sb.Begin(); foreach (Enemy e in Enemies) e.Draw(sb, gameCamera); sb.End(); }
public void Draw(SpriteBatch sb, Camera gameCamera) { /// CAMERA STUFF: subtract the camera position from the enemy's draw position sb.Draw(EnemyManager.Instance.spriteSheets["soldier"], Position - gameCamera.Position, new Rectangle(FRAME_WIDTH * currentFrame, 0, FRAME_WIDTH, FRAME_HEIGHT), Color.White, 0f, new Vector2(FRAME_WIDTH / 2, FRAME_HEIGHT), 1f, faceDir == 1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f); }
public void Draw(SpriteBatch sb, Camera gameCamera) { sb.Begin(); /// CAMERA STUFF: subtract the camera position from the tile draw position sb.Draw(spriteSheet, Position - gameCamera.Position, new Rectangle(FRAME_WIDTH * currentFrame,0,FRAME_WIDTH, FRAME_HEIGHT), Color.White, 0f, new Vector2(FRAME_WIDTH/2, FRAME_HEIGHT), 1f, faceDir==1 ? SpriteEffects.None : SpriteEffects.FlipHorizontally, 0f); sb.End(); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { camera = new Camera(GraphicsDevice.Viewport); base.Initialize(); }
/// <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); //load tilemap tilemap = Content.Load<Tilemap>("NNmap1"); //load player player = new Player(); player.LoadContent(Content); player.Tilemap = tilemap; player.LayerIndex = tilemap.PlayerStart.Layer; //need to modify this slightly more than 1 tile to the right player.Position = tilemap.PlayerStart.Position + new Vector2(60, 20); //target 30 fps for sped-up play, minimum for normal collision function //will need to scale this with time scale: based on framerate on desktop computer this.TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 60.0f); //heart = Content.Load<Texture2D>("heart"); //load camera camera = new Camera(GraphicsDevice, tilemap); camera.Target = player; //enemies = new List<Enemy>(); //if (tilemap.EnemyLocations != null) //{ // foreach (EnemyStart e in tilemap.EnemyLocations) // { // enemies.Add(new Enemy(e.MonsterType, e.Layer, e.Position)); // } //} //gems = new List<Gem>(); //if (tilemap.Gems != null) //{ // foreach (GemLocation g in tilemap.Gems) // { // gems.Add(new Gem(g.GemType, g.Layer, g.Position)); // } //} //Licensed under Creative Commons Attribution - from freemusicarchive.org //bgSong = Content.Load<Song>("Sounds/Rolemusic - Leafless_Quince_Tree"); spriteFont = Content.Load<SpriteFont>("SpriteFont1"); //MediaPlayer.Play(bgSong); gameState = GameState.Start; }
/// <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); menuScreen = new MenuScreen(this); mGameWorld = new World(this); camera = new Camera(spriteBatch, this); mGameWorld.worldWidth = Width; mGameWorld.worldHeight = Height; mGameWorld.camera = camera; mGameWorld.menuScreen = menuScreen; mGameWorld.LoadContent(Content); menuScreen.LoadContent(); // TODO: use this.Content to load your game content here }
/// <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); //load tilemap tilemap = Content.Load<Tilemap>("Map2"); //load player player = new Player(); player.LoadContent(Content); player.Tilemap = tilemap; player.LayerIndex = tilemap.PlayerStart.Layer; player.Position = tilemap.PlayerStart.Position; //heart = Content.Load<Texture2D>("heart"); //load camera camera = new Camera(GraphicsDevice, tilemap); camera.Target = player; //enemies = new List<Enemy>(); //if (tilemap.EnemyLocations != null) //{ // foreach (EnemyStart e in tilemap.EnemyLocations) // { // enemies.Add(new Enemy(e.MonsterType, e.Layer, e.Position)); // } //} //gems = new List<Gem>(); //if (tilemap.Gems != null) //{ // foreach (GemLocation g in tilemap.Gems) // { // gems.Add(new Gem(g.GemType, g.Layer, g.Position)); // } //} //Licensed under Creative Commons Attribution - from freemusicarchive.org //bgSong = Content.Load<Song>("Sounds/Rolemusic - Leafless_Quince_Tree"); spriteFont = Content.Load<SpriteFont>("SpriteFont1"); //MediaPlayer.Play(bgSong); gameState = GameState.Start; }