Closed compmstr closed 4 years ago
Hey @compmstr ,
This is a really cool feature, and I definitely want to add it, thanks! Before merging this though, I would like to explore an idea with you. How about we make the uv rect a resource? A crop. That way, there would be no need for IMAGE-PORTION
, and crops, since they are resources could easily be reused. You could load all characters from a sprite sheet into resource variables and then use them as needed. Please take a look at the following example:
(defsketch image-test
((title "Image test")
(width 400)
(height 400)
(img (load-resource "test.png")))
(background (rgb 1 1 0.5))
(image (crop img 0 0 128 64) 50 150)
;; but also
(let ((hero (crop img 0 0 128 64)))
(image hero 50 150)))
I'd really like to hear your thoughts about this.
Thanks again, Danilo
That seems like a much easier interface. I'll try setting up an image subclass with the extra field, then I can just return the extra value from shader-color-texture-values
, and do with-uv-rect
when needed in draw-shape
. Does that sound like it would work?
Yup, looks like a clean solution to me!
@compmstr Awesome, thanks! https://www.dropbox.com/s/nsgodg0mostn844/Screen%20Recording%202020-04-13%20at%2000.09.28.mov?dl=0
Merging!
@vydd :+1: Thanks for the feedback!
This will allow users to use things like sprite sheets and tile maps without needing a single image per frame/tile.
Added helper function to generate pixel-based uv rects with
pixel-uv-rect
Example code: The two sprites being accessed are at (0, 0 -> 128, 64) and (0, 64 -> 128, 64).