mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-02-05 07:24:30 +01:00
Updated Your first game in Ebiten! (markdown)
parent
46b8d054a5
commit
0e318f5640
@ -41,9 +41,9 @@ import (
|
||||
|
||||
Anything in the game is **always being updating** (or refreshing), sometimes you can heard people talked about FPS, it means **frames per second**, we would have to **clean the previous screen** and **refresh the screen** each time **we move an element**, so **the element won't leave a long track** on the screen like a snake 🐍.
|
||||
|
||||
If we want to display a text on the screen, **it will be disappeared before we see it**, Why? Because we didn't **keep it on the screen**, to do this, we'll need to call a `update()` function **per frame**, then put our code inside of the function, so the text will keep on the screen.
|
||||
If we want to display a text on the screen, **it will be disappeared before we see it**, Why? Because we didn't **keep it on the screen** to do this, we'll need to call a `update()` function **per frame**, then put our code inside of the function, so the text will keep on the screen.
|
||||
|
||||
To display a text, we can use `ebitenutil.DebugPrint(image, text)`, it's a function for **displaying a debug information**, but we can use it to display a text also.
|
||||
To display a text, we can use `ebitenutil.DebugPrint(image, text)`, which is a function for **displaying a debug information**, but we can use it to display a text also.
|
||||
|
||||
```go
|
||||
func update(screen *ebiten.Image) error {
|
||||
@ -53,15 +53,15 @@ func update(screen *ebiten.Image) error {
|
||||
}
|
||||
```
|
||||
|
||||
`screen *ebiten.Image` is **the main canvas in Ebiten** (You can think it as the **main layer of the screen**), and we are going to use `ebitenutil.DebugPrint` to print a `Our first game in Ebiten!` text on our screen.
|
||||
`screen *ebiten.Image` is **the main canvas in Ebiten** (you can think it as the **main layer of the screen**), and we are going to use `ebitenutil.DebugPrint` to print a `Our first game in Ebiten!` text on our screen.
|
||||
|
||||
But hey! it's not done yet, because **you'll need to tell Ebiten to run your `update()` function per frame**.
|
||||
But hey! It's not done yet, because **you'll need to tell Ebiten to run your `update()` function per frame**.
|
||||
|
||||
## Initialize Ebiten
|
||||
|
||||
It's time to configure Ebiten thoguh `ebiten.Run(update, width, height, scale, title)`, it tells **what function to loop**, what title should our game be, and the size of the window.
|
||||
It's time to configure Ebiten through `ebiten.Run(update, width, height, scale, title)`. This tells **what function to loop**, what title should our game be, and the size of the window.
|
||||
|
||||
* `update` Is the parameter that you would need to pass a function which will **always be called at the each of the frame**, and yes! **We will pass our `update()` function though here**.
|
||||
* `update` is the parameter that you would need to pass a function which will **always be called at the each of the frame**, and yes! **We will pass our `update()` function though here**.
|
||||
* `width` and `height` are the **width** and the **height** of the game window.
|
||||
* `scale` is the value that will scale your game window, for example if you set it as `2` and draw a `16x16` canvas on the screen it'll be rendered as 32x32 (twice larger).
|
||||
* `title` is the title of the game window.
|
||||
@ -74,7 +74,7 @@ func main() {
|
||||
}
|
||||
```
|
||||
|
||||
This will generate a **320x240 game window** and **it will be scaled twice larger** (so it's acutally a 640x480 window), and the window **will be titled as `Hello world!`**.
|
||||
This will generate a **320x240 game window** and **it will be scaled twice larger** (so it's actually a 640x480 window), and the window **will be titled as `Hello world!`**.
|
||||
|
||||
# Review
|
||||
|
||||
@ -100,7 +100,7 @@ func main() {
|
||||
|
||||
# Run
|
||||
|
||||
Your first game with Ebiten written in Golang is quietly done! Now execute it though the following command in **your terminal**.
|
||||
Your first game with Ebiten written in Go is quietly done! Now execute it though the following command in **your terminal**.
|
||||
|
||||
```go
|
||||
go run ./main.go
|
||||
|
Loading…
Reference in New Issue
Block a user