Skip to content

Commit

Permalink
minor update
Browse files Browse the repository at this point in the history
  • Loading branch information
temidaradev committed Jan 1, 2025
1 parent 717edb2 commit 1faad98
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 38 deletions.
12 changes: 3 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Important thing is create a folder and put every single tile item (.png) like th

and then you can use that function easily like this: `var Tile = esset.GetMultipleAssets(assets, "path/to/your/*.png")` Because of you are selecting more than 1 image our `*ebiten.Image` is a slice you can select by index like this: `TileComponent := assets.Tile[0]` or if you need to get random asset from that folder you can do like this: `TileRandom := assets.Tile[rand.Intn(len(assets.Tile))]`

## UseFont
## DrawText

For fonts you have to embed fonts seperataly like this:

Expand All @@ -38,14 +38,8 @@ For fonts you have to embed fonts seperataly like this:
var MyFont []byte
```

After that you should create a `&text.DrawOptions{}` in your `Draw()` func like this:
No need to create a special DrawOptions for this. Just enter X and Y after font size. Lastly add your color.

```
opF := &text.DrawOptions{}
opF.GeoM.Translate(x, y)
opF.ColorScale.ScaleWithColor(color.White)
```

After that you can use `esset.UseFont` func like this: `esset.UseFont(screen, assets.MyFont, "wassup", 24, opF)`
After that you can use `esset.DrawText` func like this: `esset.UseFont(screen, assets.MyFont, "wassup", 24, 100, 50, color.White)`

Much thanks to [@m110](https://github.com/m110) for source support <3
8 changes: 7 additions & 1 deletion esset.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"embed"
"image"
"image/color"
_ "image/png"
"io/fs"
"log"
Expand Down Expand Up @@ -44,7 +45,7 @@ var (
fontFaceSource *text.GoTextFaceSource
)

func UseFont(screen *ebiten.Image, data []byte, str string, fontSize int, op *text.DrawOptions) {
func DrawText(screen *ebiten.Image, data []byte, str string, fontSize int, posX, posY float64, color color.Color) {
s, err := text.NewGoTextFaceSource(bytes.NewReader(data))
if err != nil {
log.Fatal(err)
Expand All @@ -56,5 +57,10 @@ func UseFont(screen *ebiten.Image, data []byte, str string, fontSize int, op *te
Size: float64(fontSize),
}

op := &text.DrawOptions{}
op.GeoM.Translate(posX, posY)
op.ColorScale.ScaleWithColor(color)
op.LayoutOptions.LineSpacing = float64(fontSize)

text.Draw(screen, str, ffs, op)
}
2 changes: 1 addition & 1 deletion example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (g *Game) Draw(screen *ebiten.Image) {
opF := &text.DrawOptions{}
opF.GeoM.Translate(245, 75)
opF.ColorScale.ScaleWithColor(color.White)
esset.UseFont(screen, assets.MyFont, "ESSET", 48, opF)
esset.DrawText(screen, assets.MyFont, "ESSET\nbib", 48, 245, 75, color.White)

op := &ebiten.DrawImageOptions{}
op.GeoM.Scale(0.3, 0.3)
Expand Down
12 changes: 3 additions & 9 deletions i18n/README_jp.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ var assets embed.FS

そして、その関数は次のように簡単に使用できます: `var Tile = esset.GetMultipleAssets(assets, "path/to/your/*.png")` 1 つ以上の画像を選択しているため、`*ebiten.Image` は次のようにインデックスで選択できるスライスです: `TileComponent := asset.Tile[0]` または、そのフォルダーからランダムなアセットを取得する必要がある場合は、次のように実行できます: `TileRandom := asset.Tile[rand.Intn(len(assets.Tile))]`

## UseFont
## DrawText

フォントの場合は、次のようにフォントを個別に埋め込む必要があります。

Expand All @@ -36,14 +36,8 @@ var assets embed.FS
var MyFont []byte
```

その後、次のように `Draw()` 関数に `&text.DrawOptions{}` を作成する必要があります
このための特別な DrawOptions を作成する必要はありません。フォント サイズの後に X と Y を入力するだけです。最後に色を追加します

```
opF := &text.DrawOptions{}
opF.GeoM.Translate(x, y)
opF.ColorScale.ScaleWithColor(color.White)
```

その後、`esset.UseFont` 関数を次のように使用できます: `esset.UseFont(screen, asset.MyFont, "wassup", 24, opF)`
その後、`esset.DrawText` 関数を次のように使用できます: `esset.DrawText(screen, asset.MyFont, "wassup", 24, 100, 50, color.White)`

ソースサポートをしてくれた [@m110](https://github.com/m110) に感謝します <3
12 changes: 3 additions & 9 deletions i18n/README_sk.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Dôležité je vytvoriť priečinok a umiestniť každú jednotlivú dlaždicu (

a potom môžete jednoducho použiť túto funkciu takto: `var Tile = esset.GetMultipleAssets(assets, "path/to/your/*.png")` Kedže vyberáte viac ako 1 obraz, náš `*ebiten.Image` je pole z ktorého môžete vyberať podľa indexu takto: `TileComponent := assets.Tile[0]`, alebo ak vám treba získať náhodný materiál z toho priečinka tak môžete takto: `TileRandom := assets.Tile[rand.Intn(len(assets.Tile))]`

## UseFont
## DrawText

Pre písma ich musíte vložiť oddelene takto:

Expand All @@ -36,14 +36,8 @@ Pre písma ich musíte vložiť oddelene takto:
var MyFont []byte
```

Potom musíte vytvoriť `&text.DrawOptions{}` vo vašej `Draw()` funkcií takto:
Na to nie je potrebné vytvárať špeciálne možnosti DrawOptions. Stačí zadať X a Y po veľkosti písma. Nakoniec pridajte svoju farbu.

```
opF := &text.DrawOptions{}
opF.GeoM.Translate(x, y)
opF.ColorScale.ScaleWithColor(color.White)
```

Potom môžete použiť `esset.UseFont` funkciu takto: `esset.UseFont(screen, assets.MyFont, "wassup", 24, opF)`
Potom môžete použiť `esset.DrawText` funkciu takto: `esset.DrawText(screen, assets.MyFont, "wassup", 24, 100, 50, color.White)`

Veľmi vďaka pre [@m110](https://github.com/m110) za podporu so zdrojom <3
12 changes: 3 additions & 9 deletions i18n/README_tr.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ bu embed ifadesini içe aktarma kısmından sonra ekleyin. Artık esset'i asset

ve sonra bu işlevi şu şekilde kolayca kullanabilirsiniz: `var Tile = esset.GetMultipleAssets(assets, "path/to/your/*.png")` 1'den fazla resim seçtiğiniz için `*ebiten.Image`'imiz şu şekilde dizine göre seçebileceğiniz bir slice'dır: `TileComponent := asset.Tile[0]` veya bu klasörden rastgele bir varlık almanız gerekiyorsa şu şekilde yapabilirsiniz: `TileRandom := asset.Tile[rand.Intn(len(assets.Tile))]`

## UseFont
## DrawText

Yazı tipleri için yazı tiplerini ayrı ayrı gömmeniz gerekir:

Expand All @@ -36,14 +36,8 @@ Yazı tipleri için yazı tiplerini ayrı ayrı gömmeniz gerekir:
var MyFont []byte
```

Bundan sonra `Draw()` fonksiyonunuzda `&text.DrawOptions{}` fonksiyonunu şu şekilde oluşturmalısınız:
Bunun için ayrı bir DrawOptions oluşturmaya gerek yok. Font büyüklüğünden sonra X ve Y ekleyin. Son olarak renginizi ekleyin.

```
opF := &text.DrawOptions{}
opF.GeoM.Translate(x, y)
opF.ColorScale.ScaleWithColor(color.White)
```

Bundan sonra `esset.UseFont` fonksiyonunu şu şekilde kullanabilirsiniz: `esset.UseFont(screen, asset.MyFont, "naber", 24, opF)`
Bundan sonra `esset.DrawText` fonksiyonunu şu şekilde kullanabilirsiniz: `esset.DrawText(screen, asset.MyFont, "naber", 24, 100, 50, color.White)`

Çok teşekkürler Kaynak desteği için [@m110](https://github.com/m110) <3

0 comments on commit 1faad98

Please sign in to comment.