Skip to content

Calling the Draw function on request #2651

Answered by hajimehoshi
maxpoletaev asked this question in Q&A
Discussion options

You must be logged in to vote

Blocking in your Update would cause various issues. I would render the last image every Draw, or use SetScreenClearedEveryFrame(false) as @mcarpenter622 suggested.

Also, I'd create a new *ebiten.Image from frame and use it.

type Game struct {
	frame  *[100][100]color.RGBA
	signal chan struct{}
	frameImage *ebiten.Image
}

func (d *Game) Trigger() {
	d.signal <- struct{}{}
}

func (d *Game) Update() error {
	select {
	case <-d.signal:
		if d.frameImage == nil {
			d.frameImage = ebiten.NewImage(100, 100)
		}
		pix := make([]byte, 4 * 100 * 100)
		for y := 0; y < 100; y++ {
			for x := 0; x < 100; x++ {
				pix[4*(100*y+x)] = d.frame[y][x].R
				pix[4*(100*y+x)+1] = d.frame[y][x].G
				pix[4*(

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by maxpoletaev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants