本文整理匯總了Golang中github.com/hajimehoshi/ebiten.Image.Fill方法的典型用法代碼示例。如果您正苦於以下問題:Golang Image.Fill方法的具體用法?Golang Image.Fill怎麽用?Golang Image.Fill使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/hajimehoshi/ebiten.Image
的用法示例。
在下文中一共展示了Image.Fill方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Draw
func (s *GamepadScene) Draw(screen *ebiten.Image) error {
screen.Fill(color.Black)
if s.buttonStates == nil {
return nil
}
f := `GAMEPAD CONFIGURATION
(PRESS ESC TO CANCEL)
MOVE LEFT: %s
MOVE RIGHT: %s
DROP: %s
ROTATE LEFT: %s
ROTATE RIGHT: %s
%s`
msg := ""
if s.currentIndex == len(gamepadStdButtons) {
msg = "OK!"
}
str := fmt.Sprintf(f, s.buttonStates[0], s.buttonStates[1], s.buttonStates[2], s.buttonStates[3], s.buttonStates[4], msg)
if err := common.ArcadeFont.DrawTextWithShadow(screen, str, 16, 16, 1, color.White); err != nil {
return err
}
return nil
}
示例2: drawBackground
func (s *GameScene) drawBackground(r *ebiten.Image) error {
if err := r.Fill(color.White); err != nil {
return err
}
w, h := imageGameBG.Size()
scaleW := ScreenWidth / float64(w)
scaleH := ScreenHeight / float64(h)
scale := scaleW
if scale < scaleH {
scale = scaleH
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(scale, scale)
op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2)
a := 0.7
m := ebiten.Monochrome()
m.Scale(a, a, a, a)
op.ColorM.Scale(1-a, 1-a, 1-a, 1-a)
op.ColorM.Add(m)
op.ColorM.Translate(0.3, 0.3, 0.3, 0)
return r.DrawImage(imageGameBG, op)
}
示例3: update
func update(screen *ebiten.Image) error {
if ebiten.IsKeyPressed(ebiten.KeySpace) {
thePlayer.MoveForward()
}
rotated := false
if ebiten.IsKeyPressed(ebiten.KeyRight) {
thePlayer.RotateRight()
rotated = true
}
if ebiten.IsKeyPressed(ebiten.KeyLeft) {
thePlayer.RotateLeft()
rotated = true
}
if !rotated {
thePlayer.Stabilize()
}
if err := screen.Fill(skyColor); err != nil {
return err
}
if err := updateGroundImage(groundImage); err != nil {
return err
}
if err := drawGroundImage(screen, groundImage); err != nil {
return err
}
tutrial := "Space: Move forward\nLeft/Right: Rotate"
msg := fmt.Sprintf("FPS: %0.2f\n%s", ebiten.CurrentFPS(), tutrial)
if err := ebitenutil.DebugPrint(screen, msg); err != nil {
return err
}
return nil
}
示例4: update
func update(screen *ebiten.Image) error {
count++
count %= 600
diff := float64(count) * 0.2
switch {
case 480 < count:
diff = 0
case 240 < count:
diff = float64(480-count) * 0.2
}
if err := tmpRenderTarget.Clear(); err != nil {
return err
}
for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(15+float64(i)*diff, 20)
op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
return err
}
}
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(0, float64(i)*diff)
if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
return err
}
}
return nil
}
示例5: Draw
func (g *Game) Draw(screen *ebiten.Image) error {
if g.boardImage == nil {
var err error
w, h := g.board.Size()
g.boardImage, err = ebiten.NewImage(w, h, ebiten.FilterNearest)
if err != nil {
return err
}
}
if err := screen.Fill(backgroundColor); err != nil {
return err
}
if err := g.board.Draw(g.boardImage); err != nil {
return err
}
op := &ebiten.DrawImageOptions{}
sw, sh := screen.Size()
bw, bh := g.boardImage.Size()
x := (sw - bw) / 2
y := (sh - bh) / 2
op.GeoM.Translate(float64(x), float64(y))
if err := screen.DrawImage(g.boardImage, op); err != nil {
return err
}
return nil
}
示例6: update
func update(screen *ebiten.Image) error {
spotLightX += spotLightVX
spotLightY += spotLightVY
if spotLightX < 0 {
spotLightX = -spotLightX
spotLightVX = -spotLightVX
}
if spotLightY < 0 {
spotLightY = -spotLightY
spotLightVY = -spotLightVY
}
w, h := spotLightImage.Size()
maxX, maxY := screenWidth-w, screenHeight-h
if maxX < spotLightX {
spotLightX = -spotLightX + 2*maxX
spotLightVX = -spotLightVX
}
if maxY < spotLightY {
spotLightY = -spotLightY + 2*maxY
spotLightVY = -spotLightVY
}
if err := maskImage.Clear(); err != nil {
return err
}
op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(spotLightX), float64(spotLightY))
if err := maskImage.DrawImage(spotLightImage, op); err != nil {
return err
}
op = &ebiten.DrawImageOptions{}
op.CompositeMode = ebiten.CompositeModeSourceOut
if err := maskImage.DrawImage(fiveyearsImage, op); err != nil {
return err
}
if err := screen.Fill(color.RGBA{0x00, 0x00, 0x80, 0xff}); err != nil {
return err
}
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{}); err != nil {
return err
}
if err := screen.DrawImage(maskImage, &ebiten.DrawImageOptions{}); err != nil {
return err
}
return nil
}
示例7: Draw
func (b *Board) Draw(boardImage *ebiten.Image) error {
if err := boardImage.Fill(frameColor); err != nil {
return err
}
for j := 0; j < b.size; j++ {
for i := 0; i < b.size; i++ {
v := 0
op := &ebiten.DrawImageOptions{}
x := i*tileSize + (i+1)*tileMargin
y := j*tileSize + (j+1)*tileMargin
op.GeoM.Translate(float64(x), float64(y))
r, g, b, a := colorToScale(tileBackgroundColor(v))
op.ColorM.Scale(r, g, b, a)
if err := boardImage.DrawImage(tileImage, op); err != nil {
return err
}
}
}
animatingTiles := map[*Tile]struct{}{}
nonAnimatingTiles := map[*Tile]struct{}{}
for t := range b.tiles {
if t.IsMoving() {
animatingTiles[t] = struct{}{}
} else {
nonAnimatingTiles[t] = struct{}{}
}
}
for t := range nonAnimatingTiles {
if err := t.Draw(boardImage); err != nil {
return err
}
}
for t := range animatingTiles {
if err := t.Draw(boardImage); err != nil {
return err
}
}
return nil
}