Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I use a custom Layout method? #8

Open
xtrn143 opened this issue Apr 29, 2023 · 2 comments
Open

How can I use a custom Layout method? #8

xtrn143 opened this issue Apr 29, 2023 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@xtrn143
Copy link

xtrn143 commented Apr 29, 2023

In mizu,struct world implements the method "Layout" from ebiten.Game interface,But I want overwrite the method,or my ebiten app draw text with chinese would be fuzzy。

if I use ebiten directly,use the code below,the text display very clear,

func (g Game) Layout(outsideWidth, outsideHeight int) (screenWidth, screenHeight int) {
	s := ebiten.DeviceScaleFactor()
	return outsideWidth * int(s), outsideHeight * int(s)
}

But if I use mizu, I didnt overwrite the method named Layout, So How do I do?

@sedyh
Copy link
Owner

sedyh commented Apr 29, 2023

Hello, since the mizu's world implements the ebiten.Game interface, you can just insert it into your ebiten.Game implementation by connecting its methods. The screen borders that it inserts into Bounds() will also change.

Here is a complete example:

package main

import (
	"log"

	"github.com/sedyh/mizu/pkg/engine"

	"github.com/hajimehoshi/ebiten/v2"
)

func main() {
	ebiten.SetVsyncEnabled(false)
	ebiten.SetWindowResizingMode(ebiten.WindowResizingModeEnabled)
	if err := ebiten.RunGame(NewGame(engine.NewGame(NewSetup()))); err != nil {
		log.Fatal(err)
	}
}

type Setup struct{}

func NewSetup() *Setup {
	return &Setup{}
}

func (s *Setup) Setup(w engine.World) {
	// Register some systems here.
        // w.Bounds() will get a modified Layout() now.
}

type Game struct {
	e ebiten.Game
}

func NewGame(e ebiten.Game) *Game {
	return &Game{e}
}

func (g *Game) Update() error {
	return g.e.Update()
}

func (g *Game) Draw(screen *ebiten.Image) {
	g.e.Draw(screen)
}

func (g *Game) Layout(w, h int) (int, int) {
	// Modify your layout here.
	g.e.Layout(w, h)
	return w, h
}

@sedyh
Copy link
Owner

sedyh commented Apr 29, 2023

Perhaps in the future, I can provide a separate callback for changing the layout, but for now this option will work.

@sedyh sedyh self-assigned this Apr 29, 2023
@sedyh sedyh added the question Further information is requested label Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants