Map won't draw to second viewport?

Sep 7, 2012 at 11:58 PM

Hello again!

I'm working to add multiplayer split screen support into my game, and while I think I'm on the right track, I'm not quite understanding something in the way xTile draws its maps-

So I have two viewports defined

Camera1 = new xTile.Dimensions.Rectangle(0, 0, 400, 600);
Camera2 = new xTile.Dimensions.Rectangle(0, 0, 400, 600);
//Width is hard coded to half the screen's width for testing purposes

I have some logic written to cause Camera1 to follow my player character, while Camera2 won't have any logic and will simply be static.

So then I have the draw method where my map's draw method is called twice, once for each viewport with the corresponding offset.

map.Draw(ScreenManager.mainGame.mapDisplayDevice, Camera1, new Location(0, 0), false);
map.Draw(ScreenManager.mainGame.mapDisplayDevice, Camera2, new Location(400, 0), false);

When I run the game, the first Draw method draws just fine in the first viewport, but the other viewport draws nothing. It's just black.

More interestingly, when I add this code:

private void OnAfterLayerDraw(object sender, LayerEventArgs layerEventArgs)
            SpriteBatch spriteBatch = ScreenManager.mainGame.mapDisplayDevice.SpriteBatchAlpha;

            if (visible)
                spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);

                foreach (GameObject entity in entities.ToList())
                    entity.Draw(spriteBatch, new Vector2(Camera1.X, Camera1.Y));

                spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend);

(being as I have Camera1 hard coded for the entity.Draw() method, it'll draw objects in the same position for both viewports) it draws the entities in both viewports, but the second viewport still doesn't draw the map. Entities still respond to collision detection, as well. So it's like, the map logic is there... but not being drawn. Not sure what I'm doing wrong?

Sep 12, 2012 at 12:38 PM

After some testing I discovered an issue related to how the display device handles region clipping internally. I will include the fix with v2.0.6 of the engine.

Sep 12, 2012 at 12:43 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Sep 12, 2012 at 9:16 PM

Works like a charm! Didn't modify my code at all- merely plugged in the new .dll's and ran it, and it looks great! Thank you so much.