We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
In "packer.imageRectToPixelRect" the coordinates for the sprite are translated incorrectly.
The rectangle from the image library has its origin at the top left while a pixel rectangle has its origin at the bottom left.
I have fixed it for me but am currently too lazy to fork.
But my packar/pack.go looks like this now:
package packer import ( "image" "github.com/dusk125/rectpack" "github.com/faiface/pixel" ) type Packer struct { rectpack.Packer pic pixel.Picture batch *pixel.Batch } func New() (pack *Packer) { pack = &Packer{ Packer: *rectpack.NewPacker(rectpack.PackerCfg{}), } return } func (pack Packer) imageRectToPixelRect(r image.Rectangle) (pr pixel.Rect) { b := pack.pic.Bounds() return pixel.R(float64(r.Min.X), b.H() - float64(r.Min.Y), float64(r.Max.X), b.H() - float64(r.Max.Y)) } func (pack *Packer) Pack() (err error) { if err = pack.Packer.Pack(); err != nil { return } pack.pic = pixel.PictureDataFromImage(pack.Packer.Image()) pack.batch = pixel.NewBatch(&pixel.TrianglesData{}, pack.pic) return } func (pack *Packer) BoundsOf(id int) pixel.Rect { return pack.imageRectToPixelRect(pack.Get(id)) } func (pack *Packer) Draw(t pixel.Target) { pack.batch.Draw(t) } func (pack *Packer) DrawSub(id int, m pixel.Matrix) { r := pack.imageRectToPixelRect(pack.Get(id)) s := pixel.NewSprite(pack.pic, r) s.Draw(pack.batch, m) } func (pack *Packer) Picture() pixel.Picture { return pack.pic } func (pack *Packer) Bounds() pixel.Rect { return pack.pic.Bounds() }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
In "packer.imageRectToPixelRect" the coordinates for the sprite are translated incorrectly.
The rectangle from the image library has its origin at the top left while a pixel rectangle has its origin at the bottom left.
I have fixed it for me but am currently too lazy to fork.
But my packar/pack.go looks like this now:
The text was updated successfully, but these errors were encountered: