From 9ad9454bea31e53eb9a6e83be4bdfadb1bb3325e Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Wed, 28 Dec 2016 10:57:45 +0900 Subject: [PATCH] Updated Tutorial:Screen, colors and squares (markdown) --- Tutorial:Screen,-colors-and-squares.md | 46 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 11 deletions(-) diff --git a/Tutorial:Screen,-colors-and-squares.md b/Tutorial:Screen,-colors-and-squares.md index 4a54b49..eeb21e7 100644 --- a/Tutorial:Screen,-colors-and-squares.md +++ b/Tutorial:Screen,-colors-and-squares.md @@ -15,13 +15,16 @@ import ( func update(screen *ebiten.Image) error { // Display the text though the debug function if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { + return err } return nil } func main() { // Initialize Ebiten, and loop the update() function - ebiten.Run(update, 320, 240, 2, "Hello world!") + if err := ebiten.Run(update, 320, 240, 2, "Hello world!"); err != nil { + panic(err) + } } ``` @@ -39,9 +42,10 @@ You will need to import the `image/color` package to create the color struct by ```go import ( + "image/color" + "github.com/hajimehoshi/ebiten" "github.com/hajimehoshi/ebiten/ebitenutil" - "image/color" ) ``` @@ -63,10 +67,14 @@ Remember the `update()` function? Yeah, the function which keeps being called by func update(screen *ebiten.Image) error { // Fill the screen with #FF0000 color - screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}) + if err := screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}); err != nil { + return err + } // Display the text though the debug function - ebitenutil.DebugPrint(screen, "Our first game in Ebiten!") + if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { + return err + } return nil } @@ -115,25 +123,41 @@ You will need to render the new image to the main screen once you've created it, Here's the fully example, we'll explain it later. The examples above were be done in the `update()` function, so let's see what should your `update()` function be this time. ```go +var square *ebiten.Image + +func init() { + // Create an 16x16 image + var err error + square, err = ebiten.NewImage(16, 16, ebiten.FilterNearest) + if err != nil { + panic(err) + } +} + func update(screen *ebiten.Image) error { // Fill the screen with #FF0000 color - screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}) + if err := screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}); err != nil { + return err + } // Display the text though the debug function - ebitenutil.DebugPrint(screen, "Our first game in Ebiten!") - - // Create an 16x16 image - square, _ := ebiten.NewImage(16, 16, ebiten.FilterNearest) + if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { + return err + } // Fill the square with the white color - square.Fill(color.White) + if err := square.Fill(color.White); err != nil { + return err + } // Create an empty option struct opts := &ebiten.DrawImageOptions{} // Draw the square image to the screen with an empty option - screen.DrawImage(square, opts) + if err := screen.DrawImage(square, opts); err != nil { + return err + } return nil }