当前位置: 首页>>代码示例>>Golang>>正文


Golang ebiten.Run函数代码示例

本文整理汇总了Golang中github.com/hajimehoshi/ebiten.Run函数的典型用法代码示例。如果您正苦于以下问题:Golang Run函数的具体用法?Golang Run怎么用?Golang Run使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Run函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: main

func main() {
	var err error
	const a0, a1, a2 = 0x40, 0xc0, 0xff
	pixels := []uint8{
		a0, a1, a1, a0,
		a1, a2, a2, a1,
		a1, a2, a2, a1,
		a0, a1, a1, a0,
	}
	brushImage, err = ebiten.NewImageFromImage(&image.Alpha{
		Pix:    pixels,
		Stride: 4,
		Rect:   image.Rect(0, 0, 4, 4),
	}, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	canvasImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	canvasImage.Fill(color.White)

	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Paint (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:DrJosh9000,项目名称:ebiten,代码行数:28,代码来源:main.go

示例2: main

func main() {
	var err error
	gophersImage, _, err = common.AssetImage("gophers.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	fiveyearsImage, _, err = common.AssetImage("fiveyears.jpg", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	maskImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	as := image.Point{128, 128}
	a := image.NewAlpha(image.Rectangle{image.ZP, as})
	for j := 0; j < as.Y; j++ {
		for i := 0; i < as.X; i++ {
			r := as.X / 2
			d := math.Sqrt(float64((i-r)*(i-r) + (j-r)*(j-r)))
			b := uint8(max(0, min(0xff, 3*0xff-int(d*3*0xff)/r)))
			a.SetAlpha(i, j, color.Alpha{b})
		}
	}
	spotLightImage, err = ebiten.NewImageFromImage(a, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Masking (Ebiten Demo)"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:carriercomm,项目名称:ebiten,代码行数:33,代码来源:main.go

示例3: Run

func (g *Game) Run(width, height, scale int, title string) error {
	ticker := time.NewTicker(time.Millisecond * 70)
	go func() {
		for range ticker.C {
			if ebiten.IsKeyPressed(ebiten.KeyR) {
				g.Score = 0
				g.newMaze()
			}

			if ebiten.IsKeyPressed(ebiten.KeyLeft) && g.canGoLeft() {
				g.X--
			}

			if ebiten.IsKeyPressed(ebiten.KeyRight) && g.canGoRight() {
				g.X++
			}

			if ebiten.IsKeyPressed(ebiten.KeyUp) && g.canGoUp() {
				g.Y--
			}

			if ebiten.IsKeyPressed(ebiten.KeyDown) && g.canGoDown() {
				g.Y++
			}
		}
	}()
	defer ticker.Stop()

	return ebiten.Run(g.update, width, height, scale, title)
}
开发者ID:peterhellberg,项目名称:maze,代码行数:30,代码来源:main.go

示例4: main

func main() {
	var err error
	bgImage, _, err = ebitenutil.NewImageFromFile("_resources/images/tile.png", ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	w, h := bgImage.Size()
	const repeat = 5
	repeatedBgImage, err = ebiten.NewImage(w*repeat, h*repeat, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}
	for j := 0; j < repeat; j++ {
		for i := 0; i < repeat; i++ {
			op := &ebiten.DrawImageOptions{}
			op.GeoM.Translate(float64(w*i), float64(h*j))
			if err := repeatedBgImage.DrawImage(bgImage, op); err != nil {
				log.Fatal(err)
			}
		}
	}
	groundImage, err = ebiten.NewImage(screenWidth, screenHeight, ebiten.FilterNearest)
	if err != nil {
		log.Fatal(err)
	}

	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "infinite scroll"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:hajimehoshi,项目名称:ebiten,代码行数:30,代码来源:main.go

示例5: main

func main() {
	flag.Parse()

	m = mandelbrot.New(*width, *height, iterations(),
		mandelbrot.Colors(hex(*inside), hex(*outside))).Image()

	if err := ebiten.Run(update, *width, *height, *scale, "Plasma GUI"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:xyproto,项目名称:mandelbrot,代码行数:10,代码来源:main.go

示例6: main

func main() {
	var err error
	if cursorImage, err = ebiten.NewImage(4, 4, ebiten.FilterNearest); err != nil {
		log.Fatal(err)
	}
	cursorImage.Fill(color.White)
	var speed, scale, width, height int
	flag.IntVar(&speed, "speed", 15, "simulation steps per second")
	flag.IntVar(&scale, "scale", 16, "pixel scale factor")
	flag.IntVar(&width, "width", 64, "width of the simulation")
	flag.IntVar(&height, "height", 64, "height of the simulation")
	flag.Parse()
	flag.Args()

	cursorPosition = image.Point{width / 2, height / 2}
	simulationTimer = time.Tick(time.Second / time.Duration(speed))
	if flag.NArg() == 1 {
		inputFileName := flag.Arg(0)
		in, err := os.Open(inputFileName)
		if err != nil {
			fmt.Println(err)
			os.Exit(1)
		}
		gifImage, err := gif.DecodeAll(in)
		if err != nil {
			log.Fatal(err)
		}
		simulationImage = gifImage.Image[0]
		simulationImage.Palette[0] = color.Transparent
	} else {
		p := color.Palette{
			color.Black,
			color.RGBA{0x88, 0, 0, 0xFF},
			color.RGBA{0xFF, 0, 0, 0xFF},
			color.RGBA{0xFF, 0x22, 0, 0xFF},
			color.RGBA{0xFF, 0x44, 0, 0xFF},
			color.RGBA{0xFF, 0x66, 0, 0xFF},
			color.RGBA{0xFF, 0x88, 0, 0xFF},
			color.RGBA{0xFF, 0xAA, 0, 0xFF},
		}
		simulationImage = image.NewPaletted(image.Rect(0, 0, width, height), p)
	}
	reloadSimulation()
	if err := ebiten.Run(update, simulationImage.Bounds().Dx(), simulationImage.Bounds().Dy(), scale, "Wired Logic"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:martinkirsche,项目名称:wired-logic,代码行数:47,代码来源:main.go

示例7: main

func main() {

	s, err := NewSprite("images/actor37_0.png")
	if err != nil {
		log.Fatal(err)
	}

	w, h := s.Size()

	s.SetScale(0.5, 0.5)

	x := (screenWidth / 2) - (float64(w) / 2 * s.ScaleX()) + (screenWidth / 3)
	y := 0 + (float64(h) / 3 * s.ScaleY())
	s.SetPosition(x, y)

	if err := Attach(s); err != nil {
		log.Fatal(err)
	}

	if err := ebiten.Run(update, screenWidth, screenHeight, 2, "Ebiten Demo"); err != nil {
		log.Fatal(err)
	}
}
开发者ID:kyokomi-sandbox,项目名称:sandbox,代码行数:23,代码来源:main.go


注:本文中的github.com/hajimehoshi/ebiten.Run函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。