GMS 2 Porting Background Issues

J

JayR

Guest
I'm trying to port an old GM1.x project over to GM2. The auto-porting works fine but a lot of compatibility scripts are being created which I have no idea how it works.

So, I'm trying to manually bring it over. Which is good as I can optimise some of the old codes plus learn what new things have been added/changed.

I have an issue. The background doesn't seem to fit the game window size.

Old GM1.x code:
Code:
switch (room) {
    case rm_logo:
        background_index[0]   = bg_splash_screen;
        background_xscale[0]  = room_width / background_width[0];
        background_yscale[0]  = room_height / background_height[0];
        background_visible[0] = true;
        break;
}
New GM2 code:
Code:
switch (room) {
    case rm_logo:
        var l = layer_get_id("Background");
        var b = layer_background_get_id(l);
        layer_background_sprite(b, bg_splash_screen);
        layer_background_xscale(b, room_width / sprite_get_width(bg_splash_screen));
        layer_background_yscale(b, room_height / sprite_get_height(bg_splash_screen));
        layer_background_visible(b, true);
        break;
}
Further details:
Code:
switch(room) {
    case rm_logo:
        scr_display(3);
        break;
}
switch (room) {
    case rm_logo:
        var l = layer_get_id("Background");
        var b = layer_background_get_id(l);
        layer_background_sprite(b, bg_splash_screen);
        layer_background_xscale(b, room_width / sprite_get_width(bg_splash_screen));
        layer_background_yscale(b, room_height / sprite_get_height(bg_splash_screen));
        layer_background_visible(b, true);
        break;
}
Code:
/// scr_display(window_size[, freesize_value]);

// A quick way to set up game window size.
// Just run this script on Game Start and it will work.

var window_size    = argument[0];
var freesize_value = undefined;

if (argument_count > 1) {
    freesize_value = clamp(argument[1], 20, 100);
}

// Display optimisation for Android mobiles.
if (os_type == os_android) {
    application_surface_enable(false);
    //texture_set_blending(false);  // Commented out due to draw text colour issue.
    texture_set_interpolation(false);
}

// Enable view.
view_enabled  = 1;
view_wview[0] = room_width;
view_hview[0] = room_height;

// Check if game is running on a PC operating system.
if (os_type == os_windows || os_type == os_macosx || os_type == os_linux) {
    // Set the width and height of the view port.
    var scr_h = display_get_height() - 64;
    var scr_w = floor(scr_h * 1920/1080);
    view_wport[0] = scr_w;
    view_hport[0] = scr_h;
  
    // Set the game window size.
    var w_size, h_size;

    switch (window_size) {
        case 0:  // Freesize
            w_size = scr_w * (freesize_value/100);
            h_size = scr_h * (freesize_value/100);
            window_set_size(w_size, h_size);
            break; 
                                
        case 1:  // 100% (fullscreen windowed)
            w_size = scr_w;
            h_size = scr_h;
            window_set_size(w_size, h_size);
            break;                 
        
        case 2:  // 75%
            w_size = scr_w * 0.75;
            h_size = scr_h * 0.75;
            window_set_size(w_size, h_size);
            break;     
        
        case 3:  // 50%
            w_size = scr_w * 0.5;
            h_size = scr_h * 0.5;
            window_set_size(w_size, h_size);
            break;             
    }
              
    // Get the monitor display resolution.
    var dis_w = display_get_width();
    var dis_h = display_get_height();
    
    // Get the center point of the monitor.
    var c_point_x = dis_w * 0.5;
    var c_point_y = dis_h * 0.5;
    
    // Set the game window position on screen.
    window_set_position(c_point_x - (w_size/2), c_point_y - (h_size/2));
    display_set_gui_maximise(w_size / display_get_width(), h_size / display_get_height());
}

// Make it happen.
view_visible[0] = 1;
 

MarceloP

Member
Hello @JayR

I'm not sure if what I found will solve your problem, but is the only thing I found "may" be different from what I expected. When setting your view, I'd suggest you to set a view through a camera, which is the best way of handling views in Gamemaker 2.

I'm no expert in cameras, so please bear with me...
For that, you'd have to use this. Therefore, I'd change your code on both places that changes "view_wport" and "view_hport" to something like:
Code:
cam0 = view_camera[0];
camera_set_view_size(cam0, room_width, room_height); // view_wview[0] = room_width; //view_hview[0] = room_height;
Code:
camera_set_view_size(cam0, scr_w, scr_h); // view_wview[0] = scr_w; //view_hview[0] = scr_h;
Unfortunately, that's my only recommendation to you. I haven't been able to pin down why your Background isn't filling your room, as far as I know, it should.
If anyone disagrees with me or has found anything that may be the problem, please let us know.
 
J

JayR

Guest
Hello @JayR

I'm not sure if what I found will solve your problem, but is the only thing I found "may" be different from what I expected. When setting your view, I'd suggest you to set a view through a camera, which is the best way of handling views in Gamemaker 2.

I'm no expert in cameras, so please bear with me...
For that, you'd have to use this. Therefore, I'd change your code on both places that changes "view_wport" and "view_hport" to something like:
Code:
cam0 = view_camera[0];
camera_set_view_size(cam0, room_width, room_height); // view_wview[0] = room_width; //view_hview[0] = room_height;
Code:
camera_set_view_size(cam0, scr_w, scr_h); // view_wview[0] = scr_w; //view_hview[0] = scr_h;
Unfortunately, that's my only recommendation to you. I haven't been able to pin down why your Background isn't filling your room, as far as I know, it should.
If anyone disagrees with me or has found anything that may be the problem, please let us know.
Yup, that was exactly the problem. Thank you!
 
Top