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

Image Glitch When Window Loses Focus #3163

Closed
1 of 11 tasks
temidaradev opened this issue Nov 21, 2024 · 9 comments
Closed
1 of 11 tasks

Image Glitch When Window Loses Focus #3163

temidaradev opened this issue Nov 21, 2024 · 9 comments

Comments

@temidaradev
Copy link
Contributor

temidaradev commented Nov 21, 2024

Ebitengine Version

v2.8.4

Operating System

  • Windows
  • macOS
  • Linux
  • FreeBSD
  • OpenBSD
  • Android
  • iOS
  • Nintendo Switch
  • PlayStation 5
  • Xbox
  • Web Browsers

Go Version (go version)

1.23.2

What steps will reproduce the problem?

Implementing assets by using esset library: var GopherIdle = esset.GetAsset(assets, "gopher/mainchar.png")

Drawing background like this:

func MakeBackground(screen *ebiten.Image) {
	for i := 0; i < 100; i++ {
		for j := 0; j < 100; j++ {
			dio := &ebiten.DrawImageOptions{}
			dio.GeoM.Translate(1800-float64(i*50), 1700-float64(j*50))
			cam.Draw(assets.Tiles[1], dio, screen)
		}
	}
}

and also I used kamera library https://github.com/setanarut/kamera and here is the code of movement:

func Axis() (axisX, axisY float64) {
	if ebiten.IsKeyPressed(ebiten.KeyW) {
		axisY -= 1
	}
	if ebiten.IsKeyPressed(ebiten.KeyS) {
		axisY += 1
	}
	if ebiten.IsKeyPressed(ebiten.KeyA) {
		axisX -= 1
	}
	if ebiten.IsKeyPressed(ebiten.KeyD) {
		axisX += 1
	}
	return axisX, axisY
}

and here is the cam.LookAt usage

        var low float64 = 0
        var high float64 = 1500

        camPosX := Clamp(g.player.X, low, high)
	camPosY := Clamp(g.player.Y, low, high)

	cam.LookAt(camPosX, camPosY)

and here is player's Update() func

func (p *Player) Update() error {
	x, y := Axis()

	p.X += x * p.speed
	p.Y += y * p.speed

	p.DIO.GeoM.Reset()

	p.DIO.GeoM.Translate(
		p.X-float64(assets.GopherIdle.Bounds().Dx()/2),
		p.Y-float64(assets.GopherIdle.Bounds().Dy()/2),
	)

	//p.X = min(max(p.X, -230), 1740)
	//p.Y = min(max(p.Y, -120), 1610)

	p.X = Clamp(p.X, -230, 1740)
	p.Y = Clamp(p.Y, -120, 1610)

	return nil
}

and here is the Draw() func

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

What is the expected result?

Stable and normal behavior of gopher.

What happens instead?

Glitchy and scary gopher

Screen.Recording.2024-11-21.at.21.04.28.mov

Anything else you feel useful to add?

No response

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 21, 2024

Please provide the entire (minimized) project to reproduce the issue

@temidaradev
Copy link
Contributor Author

https://github.com/temidaradev/RpiZeroWEbiten.git here is the repo

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 21, 2024

Could you minimize the source code to reproduce this issue?

@temidaradev
Copy link
Contributor Author

Could you minimize the source code to reproduce this issue?

OK, I tried to minimize it by putting important codes

@hajimehoshi
Copy link
Owner

hajimehoshi commented Nov 21, 2024

OK, I tried to minimize it by putting important codes

Unfortunately this is not enough. Your code depends on libraries like github.com/setanarut/kamera/v2 and there might be an issue there. Please minimize it or ask the author of the library.

EDIT: Does this issue happen without the kamera library?

@temidaradev
Copy link
Contributor Author

ah wait let me test it

@temidaradev
Copy link
Contributor Author

ah yes when I tried to use screen.DrawImage(assets.GopherIdle, p.DIO) instead of cam.Draw(assets.GopherIdle, p.DIO, screen) my gopher doesn't do any flicker or glitches

@hajimehoshi
Copy link
Owner

So there might be an issue there. Ask the author.

@hajimehoshi hajimehoshi closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
@setanarut
Copy link
Contributor

setanarut commented Nov 21, 2024

This is caused by faulty code. Draw and GeoM are incorrectly drawn twice. This is not caused by the Kamera package. (code of @temidaradev)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants