17cupsofcoffee / tetra

🎮 A simple 2D game framework written in Rust
MIT License
907 stars 63 forks source link

Draft: add texture offsets for spritesheets #339

Closed fililip closed 1 year ago

fililip commented 1 year ago

Add the ability to draw texture parts, as opposed to whole textures only. This branch adds a texture_offset: Vec4 parameter to DrawParams, as well as its initializer function.

Marking this as draft as I'm unsure whether using scale and texture_offset is a good idea compared to implementing something like a Rectangle class from MonoGame/XNA. I'm open to suggestions.

17cupsofcoffee commented 1 year ago

You can already draw subsections of a texture via Texture::draw_region - does that function not fulfil your needs?

For context, before 0.6, DrawParams used to have a clip parameter that did the same thing as texture_offset. I was never totally happy with this though, as it made things confusing when drawing things that aren't textures (what would it mean to clip a Mesh, for example?).

fililip commented 1 year ago

Oh, I'm terribly sorry, I didn't notice that function at all. Yes, it does fulfil my needs.

Thanks for the help!