not-fl3 / macroquad

Cross-platform game engine in Rust.
Apache License 2.0
3.04k stars 297 forks source link

Overriding mouse position and camera when using `macroquad::ui` #709

Closed ElnuDev closed 3 months ago

ElnuDev commented 3 months ago

Hello! I'm using macroquad for developing a pixel art game and it's going quite well so far, and I'd like to give a shot at creating some UI with macroquad::ui. However, in order to get pixel-perfect rendering, I'm doing some odd things with how I'm handling rendering that I'm not sure how to make work with the UI module. Specifically, I'm a) first rendering everything to a small texture and then re-rendering it scaled up to a higher resolution with no filter to ensure all elements are pixel-perfect, then b) internally transforming the mouse position to be in the space of this smaller render texture when handling mouse events. In order to render everything to the smaller texture, I'm using set_camera and then switching back to set_default_camera for rendering the render texture.

However, it seems that the UI system is using some custom rendering logic under the hood, since even if I run calls to root_ui() while my camera is enabled, they don't get rendered to my render texture. Is there any way to get around this? Furthermore, even if there was a way, the UI system would end up using incorrect mouse coordinates.

I understand if this is something out of scope for macroquad, but I just wanted to ask for any advice in terms of going about implementing this, because it would be nice if I could use macroquad::ui rather than implementing my own system from scratch.

Thanks in advance! And thank you for this excellent crate, it's been a joy to use.

ElnuDev commented 3 months ago

I'm probably going to close this because upon more thought I don't think a render texture is necessary to enforce the UI being pixel perfect. I'll reopen if I come across an issue