This is the article I wrote for MarkUp Magazine. Hope you enjoy!
*Note: The article is in plain text. If you want to see the article with the included formating and pictures, please check out the issue of MarkUp Magazine here
Split Screen Tutorial
Multiplayer games are huge these days. Many games you find use a split-screen system to allow two or more players to play on the same computer. Many beginner level GM users have some problems when making split screen games. The main issue is adding an overlay, to display a score, timer, etc. The problem that a lot of people seem to be having is that when you add an overlay, and one player enters the other’s view, the overlay is shown in the wrong view, and it looks absolutely horrible (Picture at right). I have two simple solutions to remedy this problem.
If you are a beginner in GML and have little to no experience, here’s what you do. First, you want to make a wall object that the players can’t pass through. Line the right border of the room with this object. You might already have a wall object around your entire room, which is great. If your game lets the players warp across the room, this wall object can be invisible and on collision warp the player. Either way, the purpose of the wall object is to cordon off the right side of your room. Now that we have our wall, we want to extend the width of our room. How ever big your overlay is, you want to add 100px buffer to the width of your overlay, then add that amount to the width of your room. This creates a 100px buffer zone between the edge of the playing field and the edge of where your overlay will be. Now you want your overlay object to draw the overlay at the right edge of your room. If you have multiple overlays, put one on top of the other (picture below of what the room should look like).
Ok, now we need to add some extra views, one for each overlay. We position those views over the overlay objects, and set the port on screen to where ever the overlays would show up in the game. So if our overlay would be placed at the top left corner of the view, that is where we would place the view of the overlays. I completed these improvements, and placed a picture below of what the game would look like. One last thing, if when your player moves all the way to the right of the screen and you can see the overlay a bit, increase the 100px buffer until you can’t see the overlay anymore.
Another solution to this problem requires a bit of GML coding under your belt. This will accomplish the same task with a little less work, but it’s a little more complicated. I recently found in the help file, a snippet of code that allows you to turn off the overlay if it is in the wrong view. The statement view_current allows you to check what the current view is. So, if the current view is the wrong one, we simply don’t display the overlay. Here’s a little what the code would look like:
{
//player 1's view is view[0]
if (view_current == 0) {
//this would be the draw functions for the overlay
draw_rectangle(view_xview[0], view_yview[0],
view_xview[0]+100, view_yview[0]+20, false)
}
}
It’s that simple. The code for player 2’s view would be the same, just change the 0 in the if statement to whatever player 2’s view is.
There you have it, two simple ways to add in overlay in your split-screen game. I hope this helps a bit to solve some of the problems people have had with split-screen games.
|