Skip to content

object_attachment alighnment breaks on window resize #110

@andrew-vos

Description

@andrew-vos

object-attachment.zip
sample project attached. the oTest moves with left-right arrows

Context: object_attachment alighnment breaks on window resize. FYR I'm testing it on windows on a 4k display.
The project start windowed on FullHD resolution, but if you resize the window or go fullscreen and try moving oTest with left-right arraws you'll notice the alignment of the object_attachment breaks

I was able to fix this by changing the function yui_world_to_gui_x_2 (and yui_world_to_gui_y_2 accordingly) to this version:

// this should replace the above but needs more testing with existing cursor behavior
/// @param {Real} x
/// @param {Id.Camera,Real} camera
function yui_world_to_gui_x_2(x, camera = 0) {
    if (view_enabled) {
        var camera_x = camera_get_view_x(view_camera[camera]);
        var camera_w = camera_get_view_width(view_camera[camera]);
        
        // Position relative to camera
        var xoffset = x - camera_x;
        
        // Convert to ratio within camera view
        var camera_ratio_x = xoffset / camera_w;
        
        // Convert directly to GUI space
        var gui_x = camera_ratio_x * display_get_gui_width();
        
        return floor(gui_x);
    }
    else {
        var room_ratio_x = x / room_width;
        var gui_x = room_ratio_x * display_get_gui_width();
        return floor(gui_x);
    }
}

...and then I realized that this is the very exact implementation of yui_world_to_gui_x without _2 suffix 😂
I don't really know why have you switched to _2 version and what was wrong with the first one, but in my game with pretty simple UI i didn't see any artifacts. and the popup is correctly aligned on 4k display as well 🙂

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions