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


Golang Image.Bounds方法代碼示例

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


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

示例1: handleCursor

func handleCursor(screen *ebiten.Image) error {
	mx, my := ebiten.CursorPosition()
	cursorMoved := image.Point{mx, my}.In(screen.Bounds()) && (mx != oldMouseCursorPosition.X || my != oldMouseCursorPosition.Y)
	oldMouseCursorPosition = image.Point{mx, my}
	if cursorMoved {
		cursorPosition = oldMouseCursorPosition
	} else {
		const cursorInterval = 6
		switch {
		case keyStates[ebiten.KeyUp]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{0, -1})
			cursorMoved = true
		case keyStates[ebiten.KeyDown]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{0, +1})
			cursorMoved = true
		case keyStates[ebiten.KeyLeft]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{-1, 0})
			cursorMoved = true
		case keyStates[ebiten.KeyRight]%cursorInterval == 0:
			cursorPosition = cursorPosition.Add(image.Point{+1, 0})
			cursorMoved = true
		}
	}
	if cursorBlinking == 127 {
		cursorBlinking = 0
	} else {
		cursorBlinking++
	}
	op := &ebiten.DrawImageOptions{}
	op.GeoM.Scale(0.25, .25)
	op.GeoM.Translate(float64(cursorPosition.X), float64(cursorPosition.Y))
	if cursorBlinking > 64 {
		op.ColorM.Scale(1, 1, 1, 0.25+float64(127-cursorBlinking)/255.0)
	} else {
		op.ColorM.Scale(1, 1, 1, 0.25+float64(cursorBlinking)/255.0)
	}
	if err := screen.DrawImage(cursorImage, op); err != nil {
		return err
	}
	if keyStates[ebiten.KeySpace] >= 0 ||
		ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
		if cursorMoved || !wasMouseButtonPressed {
			if err := togglePixel(cursorPosition); err != nil {
				return err
			}
			wasMouseButtonPressed = true
		}
	} else {
		wasMouseButtonPressed = false
	}
	return nil
}
開發者ID:martinkirsche,項目名稱:wired-logic,代碼行數:52,代碼來源:main.go

示例2: update

func (r *recorder) update(screen *ebiten.Image) error {
	if err := r.inner(screen); err != nil {
		return err
	}
	if r.currentFrame == r.frameNum {
		return nil
	}
	if r.currentFrame%r.skips == 0 {
		if r.gif == nil {
			num := (r.frameNum-1)/r.skips + 1
			r.gif = &gif.GIF{
				Image:     make([]*image.Paletted, num),
				Delay:     make([]int, num),
				LoopCount: -1,
			}
		}
		s := image.NewNRGBA(screen.Bounds())
		draw.Draw(s, s.Bounds(), screen, screen.Bounds().Min, draw.Src)

		img := image.NewPaletted(s.Bounds(), r.palette())
		f := r.currentFrame / r.skips
		r.wg.Add(1)
		go func() {
			defer r.wg.Done()
			draw.FloydSteinberg.Draw(img, img.Bounds(), s, s.Bounds().Min)
			r.gif.Image[f] = img
			r.gif.Delay[f] = r.delay()
		}()
	}

	r.currentFrame++
	if r.currentFrame == r.frameNum {
		r.wg.Wait()
		if err := gif.EncodeAll(r.writer, r.gif); err != nil {
			return err
		}
	}
	return nil
}
開發者ID:DrJosh9000,項目名稱:ebiten,代碼行數:39,代碼來源:gif.go


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