2021SC@SDUSC
在分析代码的过程中让我们先学习一下如何显示图片和文字
1、Ebiten在窗口显示文字
package main
import (
"fmt"
"log"
"github.com/hajimehoshi/ebiten"
"github.com/hajimehoshi/ebiten/ebitenutil"
)
/*
空结构体,实现了ebiten.Game接口。
*/
type Game struct{}
/*
Update()是一个成员函数,自动调用
因为这是一个游戏开发的库,界面是需要实时更新的
因此每一个周期,都会更新一次,也就是调用一次Update函数
更新周期是1/60秒,也就是一秒会更新60次
*/
func (g *Game) Update() error {
return nil
}
/*
Draw()用于渲染界面,也是个会自动调用的函数
这个函数的自动调用频率和你电脑显示器的刷新频率一样
screen表示GUI窗口显示的对象,这里是在该窗口输出"Hello, World!"
*/
func (g *Game) Draw(screen *ebiten.Image) {
ebitenutil.DebugPrint(screen, "Hello, World!")
}
/*
Layout()函数的返回值表示显示窗口里面逻辑上屏幕的大小
官网上说参数outsideWidth和outsideHeight是显示在桌面的窗口大小
这里是固定大小640*480
*/
func (g *Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
return 640, 480
}
func main() {
// 设置窗口大小是640*480