当前位置: 首页>>代码示例>>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;未经允许,请勿转载。