Run is called to create a window, initialize everything, and start the main loop. Once this function returns, the game window has been closed already. You can supply a lot of options within `RunOptions`, and your starting `Scene` should be defined in `defaultScene`.
(o RunOptions, defaultScene Scene)
| 156 | // the game window has been closed already. You can supply a lot of options within `RunOptions`, and your starting |
| 157 | // `Scene` should be defined in `defaultScene`. |
| 158 | func Run(o RunOptions, defaultScene Scene) { |
| 159 | // Setting defaults |
| 160 | if o.FPSLimit == 0 { |
| 161 | o.FPSLimit = 60 |
| 162 | } |
| 163 | |
| 164 | if o.MSAA < 0 { |
| 165 | panic("MSAA has to be greater or equal to 0") |
| 166 | } |
| 167 | |
| 168 | if o.MSAA == 0 { |
| 169 | o.MSAA = 1 |
| 170 | } |
| 171 | |
| 172 | if len(o.AssetsRoot) == 0 { |
| 173 | o.AssetsRoot = "assets" |
| 174 | } |
| 175 | |
| 176 | if o.Update == nil { |
| 177 | o.Update = &ecs.World{} |
| 178 | } |
| 179 | |
| 180 | if o.GlobalScale.X <= 0 || o.GlobalScale.Y <= 0 { |
| 181 | o.GlobalScale = Point{X: 1, Y: 1} |
| 182 | } |
| 183 | |
| 184 | opts = o |
| 185 | |
| 186 | // Create input |
| 187 | Input = NewInputManager() |
| 188 | if opts.StandardInputs { |
| 189 | log.Println("Using standard inputs") |
| 190 | |
| 191 | Input.RegisterButton("jump", KeySpace) |
| 192 | Input.RegisterButton("action", KeyEnter) |
| 193 | |
| 194 | Input.RegisterAxis(DefaultHorizontalAxis, AxisKeyPair{KeyA, KeyD}, AxisKeyPair{KeyArrowLeft, KeyArrowRight}) |
| 195 | Input.RegisterAxis(DefaultVerticalAxis, AxisKeyPair{KeyW, KeyS}, AxisKeyPair{KeyArrowUp, KeyArrowDown}) |
| 196 | |
| 197 | Input.RegisterAxis(DefaultMouseXAxis, NewAxisMouse(AxisMouseHori)) |
| 198 | Input.RegisterAxis(DefaultMouseYAxis, NewAxisMouse(AxisMouseVert)) |
| 199 | } |
| 200 | |
| 201 | Files.SetRoot(opts.AssetsRoot) |
| 202 | currentUpdater = opts.Update |
| 203 | |
| 204 | // And run the game |
| 205 | if opts.HeadlessMode { |
| 206 | if opts.Width == 0 { |
| 207 | opts.Width = headlessWidth |
| 208 | } |
| 209 | if opts.Height == 0 { |
| 210 | opts.Height = headlessHeight |
| 211 | } |
| 212 | windowWidth = float32(opts.Width) |
| 213 | windowHeight = float32(opts.Height) |
| 214 | gameWidth = float32(opts.Width) |
| 215 | gameHeight = float32(opts.Height) |