This is what we will set our grid’s Rect Transform to be. If we multiply these numbers by 70% (0.7) we get 1008 x 1792. If you recall, our game’s screen size is set for 1440 x 2560 pixels. In the above screenshot, you can see that the Tetris grid takes up 70% of the screen, leaving plenty of room on all sides for UI elements. That means we want our Tetris grid’s end result by the end of this article to look something like this: Because of this, we want our game’s play space to be roughly 70% of the actual screen size. If you think about the way an actual Tetris game is laid out, you will realize there is room on either side of the screen for UI elements. Now… it’s time to get a bit mathematical. While you’re at it, make sure its wrap mode is set to “Repeat.” See the screenshot below for a visual. If you are unable to drag and drop the grid object onto the Raw Image, make sure you have changed the grid’s texture type to “Default” first. Once you have a raw image added to the scene, rename it “Grid” and attach one of the grid pieces from my enhanced starter pack.
Make sure you don’t choose just “image” or else this won’t work. You can do this by clicking “GameObject” in the top window and then adding it from under UI –> Raw Image. In order to do this, we need to create a raw image. The goal here is to create a grid that perfectly matches one Unity world unit for each grid block, in both length and height. Now that the Tetris pieces are in place, it’s time to create a grid system. So this means a 10 x 22 grid will be counted as 0-9 and 0-21.Īlso, for this game we will be using a 1440 x 2560 game size, which is the same screen size as the Samsung Galaxy S7 Setting it to 9 and 21 would put the bottom-left corner in the upper-right most square. That means we want to get our game to a point where if we set both the X and Y coordinates of any given Tetris piece, they will appear in the bottom-left corner of the grid. The Tetris pieces will have a pivot point in the bottom left corner. The idea here is that we have a 10 x 22 Tetris grid. Ultimately, we want to create something that looks like this: In this entry, we are going to take the first steps towards creating our Tetris clone, which means creating a game grid.
In this blog post and video, you are going to learn how to create a Tetris grid that will allow you to easily and seamlessly place and move your Tetris pieces.
I also created a free enhanced Tetris starter pack that gives you most of the game assets you will need to get your game started. In the previous blog post we introduced our free Tetris clone and talked about how to find and import game assets.