Rendering the Spaces, Board, and Tokens Solution5:11 with Ashley Boucher
See the solution for rendering the Space, Board, and Token objects.
Jump to Solution Timestamps
1:40 - drawSVGSpace() solution
2:43 - drawHTMLBoard() solution
4:03 - drawHTMLToken() solution
Some Background on SVGs
SVG stands for Scalable Vector Graphics. MDN describes SVG as an XML-based markup language for describing two dimensional based vector graphics. It says “SVG is essentially to graphics what HTML is to text”. Essentially, SVG is a way to write, or describe, a graphic element in code. SVGs are great for displaying shapes on your website or app.
You might be wondering: why not just use CSS? Well, CSS can do a lot, for sure. But the reason SVGs are the right choice for this part of the app is because it offers the ability to clip and mask objects. On a real life “Four in a Row” board, the spaces that the tokens are dropped into are actually holes in the board. To recreate this “hole” effect in our game, we have to use SVGs masking capabilities.
Line 17 in the
drawSVGSpace() method in the Space.js file is unnecessary. Remember when I mentioned that apps often go through many iterations? Adding the
data-column attribute to the SVG element was important in a previous iteration, but not used in the final project. Feel free to ignore it. Its presence doesn't anything, but you won't see it utilized in the rest of the course.
You need to sign up for Treehouse in order to download course files.Sign up