How do you do splitscreens?

Is it possible to create a splitscreen in Codea?

Sorry, this will be a little brief. I’m in a rush. If you want more help, LMK. But basically, just use the clip() function. Look here for a little help: http://twolivesleft.com/Codea/Reference/#detail/index/clip
So say this:

clip(0,0,WIDTH/2,HEIGHT/2)
--draw your left hand stuff here
clip(WIDTH/2,HEIGHT/2,WIDTH/2,HEIGHT/2)
--draw your right hand stuff here
clip() --disables it

Hope that helps! Good luck!

Hi IJazmith. It’s definitely possible, here’s an example - https://twitter.com/#!/peteroyle/status/183485666351513600

That’s also an example of what happens when you don’t follow Zoyt’s advice about clipping - the starburst effect spills outside of player one’s game area.

Another main point is that the game was originally only single player. So to make it support split-screen I basically created two instances of the game board and applied a different visual transformation to each one to get them to appear in the correct spots. I then needed to apply the corresponding reverse transformation to each of the touch inputs before passing them to each game board for processing. There was definitely a lot of trial and error and hair loss in getting the transformations correct, but it all works quite well in the end. Later on I’ll upload my transformation class. Hopefully it will make sense and be reusable outside of my game.

if you’re thinking about a not so much action game, you could create an image as a players view with setcontext() and display that as a sprite…
but performance would be very very slow…

OK I’ve extracted the code into an example here: https://gist.github.com/2652743 I’m not saying this is the best approach, but it worked for me and I didn’t have to change much of my existing single-player game using this approach.

The example includes a main menu where you select 1 or 2 players, and a dummy game where you just paint the screen in your randomly designated colour.

I guess the key parts are Menu:startGame(numPlayers) where, depending on the number of players, it either initialises one game board without any transformation (full screen) or two game boards, each with the appropriate transformation. Main:touched(touch) ensures all touches are passed to all registered game boards.

GameBoard:draw() applies transformation and clipping if necessary before rendering itself, thus causing it to render on its own half of the screen in two player mode. Because this transformation is only visual each game board’s logical dimensions are still full screen and so when we get a touch on one of the visual game boards, we need to map it to the corresponding logical full-screen coordinates for that game board. This mapping obviously happens to be the reverse of the visual transformation. That’s why GameBoard:touched(t) applies the reverse transformation to the given touch point to map it back to the full screen before using it. To give an example, if in two player mode you touched the bottom-left of the screen, that would correspond to the bottom-right side of player one’s screen, and so that touch needs to be mapped to a point at the bottom-right of full screen before being processed by player one’s board. When player two’s board applies its own transformation however, it would appear as if the point lands way above the top of the screen, and so the touch should be ignored.

Hope that makes sense. I’m not great at explaining things I barely understand :slight_smile: