go language ebiten start interface

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
    insert image description here
  • Note: RunGame() itself is a continuously looping function
  • This is a simple ebiten start

Guess you like

Origin blog.csdn.net/JUIU9527/article/details/131262184