gopxl / pixel

A hand-crafted 2D game library in Go.
MIT License
225 stars 9 forks source link

Confusion about imdraw documentation #54

Open duysqubix opened 11 months ago

duysqubix commented 11 months ago
edgeDebug := imdraw.New(nil)

for !win.Closed() {
    // .....

    edgeDebug.Clear()
    //edgeDebug.Reset()
    edgeDebug.Color = colornames.Red
    edgeDebug.Push(points...)
    edgeDebug.Line(2)

    // .....

    win.Draw(edgeDebug)
}

According to documentation below

// Clear removes all drawn shapes from the IM. This does not remove Pushed points. func (imd *IMDraw) Clear()

// Reset restores all point properties to defaults and removes all Pushed points. // // This does not affect matrix and color mask set by SetMatrix and SetColorMask. func (imd *IMDraw) Reset()

Pushing new points in the main loop is no good since Clear() doesn't empty already pushed points but for some reason it works just fine. Only the recently pushed points are drawn to the screen. Am I missing something?

Also, Reset() supposedly removes all the pushed points but in this case it doesn't work. All the points pushed up until that moment is drawn to the screen. That's probably because old points were already drawn to the framebuffer and reset doesn't clear the buffer but it's really confusing.

Another nitpick would be that even If I use both there is no way to completely reset an imdraw object since it doesn't affect matrix and color mask.

So what's the best way to have a dynamically changing imdraw setup?

Thanks

Original issue: https://github.com/faiface/pixel/issues/216