Updated Tutorial:Screen, colors and squares (markdown)

Hajime Hoshi 2017-03-04 12:08:24 +09:00
parent 4c7c138a89
commit b2d6b48e8c

@ -14,9 +14,7 @@ import (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
// Display the text though the debug function // Display the text though the debug function
if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { ebitenutil.DebugPrint(screen, "Our first game in Ebiten!")
return err
}
return nil return nil
} }
@ -67,14 +65,10 @@ Remember the `update()` function. The function which keeps being called by Ebite
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
// Fill the screen with #FF0000 color // Fill the screen with #FF0000 color
if err := screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}); err != nil { screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff})
return err
}
// Display the text though the debug function // Display the text though the debug function
if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { ebitenutil.DebugPrint(screen, "Our first game in Ebiten!")
return err
}
return nil return nil
} }
@ -111,17 +105,11 @@ func update(screen *ebiten.Image) error {
// ... // ...
if square == nil { if square == nil {
// Create an 16x16 image // Create an 16x16 image
var err error square, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
square, err = ebiten.NewImage(16, 16, ebiten.FilterNearest)
if err != nil {
return err
}
} }
// Fill the square with the white color // Fill the square with the white color
if err := square.Fill(color.White); err != nil { square.Fill(color.White)
return err
}
// ... // ...
} }
@ -141,36 +129,24 @@ var square *ebiten.Image
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
// Fill the screen with #FF0000 color // Fill the screen with #FF0000 color
if err := screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff}); err != nil { screen.Fill(color.NRGBA{0xff, 0x00, 0x00, 0xff})
return err
}
// Display the text though the debug function // Display the text though the debug function
if err := ebitenutil.DebugPrint(screen, "Our first game in Ebiten!"); err != nil { ebitenutil.DebugPrint(screen, "Our first game in Ebiten!")
return err
}
if square == nil { if square == nil {
// Create an 16x16 image // Create an 16x16 image
var err error square, _ = ebiten.NewImage(16, 16, ebiten.FilterNearest)
square, err = ebiten.NewImage(16, 16, ebiten.FilterNearest)
if err != nil {
return err
}
} }
// Fill the square with the white color // Fill the square with the white color
if err := square.Fill(color.White); err != nil { square.Fill(color.White)
return err
}
// Create an empty option struct // Create an empty option struct
opts := &ebiten.DrawImageOptions{} opts := &ebiten.DrawImageOptions{}
// Draw the square image to the screen with an empty option // Draw the square image to the screen with an empty option
if err := screen.DrawImage(square, opts); err != nil { screen.DrawImage(square, opts)
return err
}
return nil return nil
} }