go language ebiten start interface
just need to implementa structureandfour methodscan
1. A structure
type Game struct{}
: Game main structure
2. Four methods
- 1.
func (g*Game)Update()error{}
//Used to implement game logic
- 2.
func (g*Game)Draw(screen *ebiten.Image){}
//Used to render the screen
- 3.
func (g*Game)Layout(outsideWidth,outsideHeight int)(screenWidth,screenHeight int){}
//Used to control the size of the image inside the window
- 4.
func (g*Game)RunGame(game *Game){}
//Used to start the game
example:
type Game struct{
}
func (g*Game)Update()error{
return nil
}
func (g*Game)Draw(screen *ebiten.Image){
}
func (g*Game)Layout(outsideWidth,outsideHeight int)(screenWidth,screenHeight int){
return 480,320
}
func main(){
ebiten.SetWindowTitle("边界限制")
ebiten.SetWindowSize(960, 640)
if err:=ebiten.RunGame(&Game{
});err!=nil{
log.Fatal("启动失败:",err)
}
}
- After running, you will find that it is a black window , then you are correct
- Note: RunGame() itself is a continuously looping function
- This is a simple ebiten start