當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Image.Size方法代碼示例

本文整理匯總了Golang中github.com/hajimehoshi/ebiten.Image.Size方法的典型用法代碼示例。如果您正苦於以下問題:Golang Image.Size方法的具體用法?Golang Image.Size怎麽用?Golang Image.Size使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/hajimehoshi/ebiten.Image的用法示例。


在下文中一共展示了Image.Size方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: 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
}
開發者ID:hajimehoshi,項目名稱:ebiten,代碼行數:26,代碼來源:game.go

示例2: update

func update(screen *ebiten.Image) error {
	for key, _ := range keyStates {
		if !ebiten.IsKeyPressed(key) {
			keyStates[key] = 0
			continue
		}
		keyStates[key]++
	}
	d := 0
	switch screenScale {
	case 1:
		d = 32
	case 2:
		d = 16
	}

	if keyStates[ebiten.KeyUp] == 1 {
		screenHeight += d
	}
	if keyStates[ebiten.KeyDown] == 1 {
		if 16 < screenHeight {
			screenHeight -= d
		}
	}
	if keyStates[ebiten.KeyLeft] == 1 {
		if 16 < screenWidth {
			screenWidth -= d
		}
	}
	if keyStates[ebiten.KeyRight] == 1 {
		screenWidth += d
	}
	if keyStates[ebiten.KeyS] == 1 {
		screenScale = 3 - screenScale // Swap 1 and 2
	}
	ebiten.SetScreenSize(screenWidth, screenHeight)
	ebiten.SetScreenScale(screenScale)

	screen.Fill(color.RGBA{0x80, 0x80, 0xc0, 0xff})
	w, h := gophersImage.Size()
	w2, h2 := screen.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(-w+w2)/2, float64(-h+h2)/2)
	if err := screen.DrawImage(gophersImage, op); err != nil {
		return err
	}

	x, y := ebiten.CursorPosition()
	msg := fmt.Sprintf(`Press arrow keys to change the window size
Press S key to change the window scale
Cursor: (%d, %d)
FPS: %0.2f`, x, y, ebiten.CurrentFPS())
	ebitenutil.DebugPrint(screen, msg)
	return nil
}
開發者ID:DrJosh9000,項目名稱:ebiten,代碼行數:55,代碼來源:main.go

示例3: updateGroundImage

func updateGroundImage(ground *ebiten.Image) error {
	if err := ground.Clear(); err != nil {
		return err
	}
	x16, y16 := thePlayer.Position()
	a := thePlayer.Angle()
	gw, gh := ground.Size()
	w, h := gophersImage.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(float64(-x16)/16, float64(-y16)/16)
	op.GeoM.Translate(float64(-w*2), float64(-h*2))
	op.GeoM.Rotate(float64(-a)*2*math.Pi/maxAngle + math.Pi*3.0/2.0)
	op.GeoM.Translate(float64(gw)/2, float64(gh)-32)
	if err := ground.DrawImage(repeatedGophersImage, op); err != nil {
		return err
	}
	return nil
}
開發者ID:hajimehoshi,項目名稱:ebiten,代碼行數:18,代碼來源:main.go

示例4: drawGroundImage

func drawGroundImage(screen *ebiten.Image, ground *ebiten.Image) error {
	w, _ := ground.Size()
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Translate(-float64(w)/2, 0)
	op.GeoM.Rotate(-1 * float64(thePlayer.lean) / maxLean * math.Pi / 8)
	op.GeoM.Translate(float64(w)/2, 0)
	op.GeoM.Translate(float64(screenWidth-w)/2, screenHeight/3)
	op.ImageParts = &groundParts{ground}
	if err := screen.DrawImage(ground, op); err != nil {
		return err
	}
	op = &ebiten.DrawImageOptions{}
	op.GeoM.Translate(-float64(w)/2, 0)
	op.GeoM.Rotate(-1 * float64(thePlayer.lean) / maxLean * math.Pi / 8)
	op.GeoM.Translate(float64(w)/2, 0)
	op.GeoM.Translate(float64(screenWidth-w)/2, screenHeight/3)
	if err := screen.DrawImage(fogImage, op); err != nil {
		return err
	}
	return nil
}
開發者ID:hajimehoshi,項目名稱:ebiten,代碼行數:21,代碼來源:main.go


注:本文中的github.com/hajimehoshi/ebiten.Image.Size方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。