Ebiten 是一个用go语言编写的开源的跨平台的2D游戏引擎。
> 安装
Ebiten在使用上跟平常的Go库没啥区别,当你的程序使用Ebiten的时候Go命令行会自动的安装Ebiten。
# 为游戏创建一个目录
mkdir yourgame
cd yourgame
# 初始化go.mod
go mod init github.com/wuyutaott/2048
# 下载ebiten
go get github.com/hajimehoshi/ebiten/v2
# 运行例子
go run -tags=example github.com/hajimehoshi/ebiten/v2/examples/rotate
看到这个截图代表Ebiten安装成功
> 例子
https://github.com/hajimehoshi/ebiten.git
的examples文件夹中有很多例子
运行方式都是
go run -tags=example github.com/hajimehoshi/ebiten/v2/examples/xxx
> Hello World
创建main.go
package main
import (
"github.com/hajimehoshi/ebiten/v2"
"github.com/hajimehoshi/ebiten/v2/ebitenutil"
"log"
)
type Game struct{}
func (g *Game) Update() error {
return nil
}
func (g *Game) Draw(screen *ebiten.Image) {
ebitenutil.DebugPrint(screen, "Hello, World!")
}
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return 320, 240
}
func main() {
ebiten.SetWindowSize(640, 480)
ebiten.SetWindowTitle("Hello, World!")
if err := ebiten.RunGame(&Game{}); err != nil {
log.Fatal(err)
}
}
> 运行
go run main.go
最后
以上就是勤奋流沙最近收集整理的关于Ebiten 安装和使用的全部内容,更多相关Ebiten内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复