class: center, middle # Creación de Videojuegos ### 2D Graphics --- class: center, middle # Lines --- # Lines * Remember triangles? * Lines are the triangles of the 2D world (kind of) * You can assemble lines into polygons * Lines connect two vertices --- class: small # Rasterization of Lines * How do we draw a line on the screen? * Pixels! * Rasterization: Take lines (or triangles, in 3D), and map them to pixels * But pixels are arranged in a rectangular grid * How do we draw diagonal lines? * Idea: Draw ideal line, and for each column of pixels make the pixel black that is closest to the line! * Bresenham's algorithm! --- # Bresenham's algorithm
--- # Bresenham's algorithm: result
--- # Aliasing
--- class: small # Anti-Aliasing * What if we use other pixels that are touched by the line, too? * Maybe not to show them in black, but some sort of gray? * How do we determine "how gray" a pixel should be? * Supersampling! * Calculate more pixels than necessary, and take the average value --- # Supersampling
--- # Supersampling: Result
--- class: small # Anti-Aliasing
--- class: small # Polygons
image/svg+xml
* Can be convex or not * Can self-overlap * *Simple* polygons: No self-intersections --- class: small # (Simple) Polygons: Flood Fill
image/svg+xml
* Start at any pixel inside the polygon * If current pixel already has the target color, or the border color: return * Otherwise, color current pixel with target color and recursively call Flood Fill for all four neighboring pixels --- # Corner cutting
image/svg+xml
* What if we want a round corner? * Idea: Take parts of the lines near the corners and start cutting --- # Corner cutting
image/svg+xml
* Now cut each of these two line segments in half, and connect the midpoints --- # Corner cutting
image/svg+xml
* Now we have three line segments * Cut each in half again, and connect the end points --- # Corner cutting
image/svg+xml
--- # Corner cutting
image/svg+xml
--- # Corner cutting
image/svg+xml
--- # Corner cutting
image/svg+xml
--- # Corner cutting * We don't need to cut each line segment in half * We can use cuts of 1/3 to 2/3, or any other fraction * This allows us to control the rounding
image/svg+xml
--- # Corner cutting with ration 1/3 to 2/3
image/svg+xml
--- # Corner cutting with ration 1/3 to 2/3
image/svg+xml
--- # Corner cutting with ration 1/3 to 2/3
image/svg+xml
--- # Subdivision Surfaces * You can basically do the same thing in 3D!
--- # Curves * Sometimes we want to draw arbitrary curves * One approach: Perform corner cutting on a polygon * Drawback: Smoothness * Other approach: Splines! --- # Splines
--- # Splines
--- # Bezier Curves
--- class: center, middle # Sprites --- # Sprites * Sometimes we want pre-drawn art: *Sprites* * A sprite is a 2D image that is drawn into the scene * Old consoles and arcade machine had hardware support for sprites * Today they are very cheap to display * Sprites can also be animated! --- # Sprite Sheets
--- # Sprite Animations
--- # Sprite Animations
```JavaScript context.drawImage(image, frameIndex * width / numberOfFrames, clip*height, width / numberOfFrames, height, 0, 0, width / numberOfFrames, height); ``` --- # Goomba
--- # Goomba, animated
--- # Sprites in Unity
--- class: middle, center # And now for something completely different ## Unity --- # The problem with Unity
--- # The problem with Unity * Unity makes it really easy to make games * This is great! * Unfortunately that also means that there are many less-than-great games made in Unity * If you make less than $100 000/year, you can use the free version * What's the problem with the free version? --- # The problem with Unity
--- # Why? * Engines used to be one of the main selling point of games * Many gamers still equate engine with game quality * And now they see many less-than-great games with a "Made with Unity" splash screen * Therefore, a game made in Unity must be terrible * Except that's not true --- # A solution?
--- class: small # References *
Sprite Sheet Animations in Unity
*
Twitter rant about game journalists emphasizing game engines
*
A counterpoint: There should be better curation on Steam, etc.
*
"Unreal simulator" for Unity