• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Backgrounds : 'zooming' & getting name

T

Tofu Heavy Industries

Guest
Hello,

I am using GMS 1.4, and I had 2 questions about backgrounds.

1) how do you get the actual name of the background of the room you're currently in ? (i.e. back_b_street)

2) I am trying to create a room + background that functions like the backgrounds on Samurai Showdown 2-4. I'll describe if youre not familiar.

In these fighting games, when the 2 fighters are close together, the background in zoomed in, and when they are far apart, the background zooms out. (see youtube for reference).

I've tried to use a bigger background then the room, and use x/yscale on the background when the 2 characters are far apart. I've also tried to maybe use views/ports on screen to achieve this effect. Nothing seems to be working. I'm going on the idea that the resolution/ screen size is not changing (ergo in SS the health bars dont shrink/expand), so I dont think i need to actually change the rooms size. Any help is appreciated.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
1) background_get_name() ;)

2) You simply need to expand the view. Set up the view to be the size you want, then in code set the new width/height based on the bbox for the player characters. The following code is just to show you how the idea behind this would work...

Code:
// STEP EVENT OF A VIEW CONTROLLER
if instance_exists(obj_player1) && instance_exists(obj_Player2)
{
var _left = room_width;
var _right = 0;
// Get the left/right maximum for the view
if obj_Player1.bbox_left < _left _left = obj_Player1.bbox_left;
if obj_Player2.bbox_left < _left _left = obj_Player2.bbox_left;
if obj_Player1.bbox_right > _right _right= obj_Player1.bbox_right;
if obj_Player2.bbox_right < _right _right= obj_Player2.bbox_right;
// Get the new width for the view, from a minimum of 640 to a maximum of the room_width (you can change 640 to whatever min width is required)
var _w = clamp(abs(_right - _left), 640, room_width);
// Set the view width
view_wview[0] = lerp(view_wview[0], _w, 0.5);
// Set the view height based on the view PORT aspect ratio
view_hview[0] = view_wport[0] * (view_hport[0] / view_wport[0]);
}
 
T

Tofu Heavy Industries

Guest
I've already tried to use that. For instance in my first room, if I use background_get_name(0) it gives me the name of the first background on the list, not the name of background currently being used by the room. If I try to use background_get_name(room), again, it just gives me the first background on the list, which is not correct. (its currently using the background that is 7 or 8).

I'm trying to get the name of background of a room when i don't know what background will be placed there, because it will be random (from a choose).
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Well, of course background_get_name(0) gives you the first one in the resource tree! All resource indices are integers starting at 0. If you want the background assigned to background 0 then you need to supply the background_index[] value, so:

Code:
name = background_get_name(background_index[0]);
That should work fine. :)
 
T

Tofu Heavy Industries

Guest
Well, of course background_get_name(0) gives you the first one in the resource tree! All resource indices are integers starting at 0. If you want the background assigned to background 0 then you need to supply the background_index[] value, so:

Code:
name = background_get_name(background_index[0]);
That should work fine. :)
thank you :)
 
T

Tofu Heavy Industries

Guest
2) You simply need to expand the view. Set up the view to be the size you want, then in code set the new width/height based on the bbox for the player characters. The following code is just to show you how the idea behind this would work...
This is what im originally using, when the sides are touched by the players, it just always stretches the background to the left.

Some notes:
obj_player1/2 flag whether to scale on not based on their X (Just obj_player1 code included, second player code is same except for using player2's X)
The cont_battle object does the actual scaling
Room size: 640x480
Background size: 1920x1080
room1 view0 not enabled
room1 View on screen w640 h480
room1 Port on screen w640 h480


Code:
//--------------------------------------------------------------------------------------
obj_player1(obj_player2 ) : Step 


if (x <= (obj_player1.sprite_width/2)) {
    x = (obj_player1.sprite_width/2);
    scaling = 1;
}
if (x >= (room_width-(obj_player1.sprite_width/2))) {     
    x = (room_width-(obj_player1.sprite_width/2));
    scaling = 1;
}

//--------------------------------------------------------------------------------------
COnt_Battle : End STep

if ((instance_exists(obj_player1)) && (instance_exists(obj_player2))){
if ((obj_player1.scaling == 1) && (obj_player2.scaling == 1)){

    if ((obj_player1.image_xscale >= 0.7) && (obj_player2.image_xscale >= 0.7)){
    obj_player1.image_xscale -= .05;
    obj_player1.image_yscale -= .05;
    obj_player2.image_xscale -= .05;
    obj_player2.image_yscale -= .05;

    
    view_wport[0] += 0.05;
    view_hport[0] += 0.05;
    
      
    
    }
            
}

if ((obj_player1.scaling == 2) && (obj_player2.scaling == 2)){
    if ((obj_player1.image_xscale <= 1) && (obj_player2.image_xscale <= 1)){
    obj_player1.image_xscale += .05;
    obj_player1.image_yscale += .05;
    obj_player2.image_xscale += .05;
    obj_player2.image_yscale += .05;
    
    }
}
}
So then i tried what you posted..and no scaling at all happens. I use the same obj_player code above, but i add in your code for Cont_battle.

Room size: 640x480
Background size: 1920x1080
room1 view0 enabled
room1 View on screen w640 h480
room1 Port on screen w640 h480

Code:
if ((instance_exists(obj_player1)) && (instance_exists(obj_player2))){
if ((obj_player1.scaling == 1) && (obj_player2.scaling == 1)){

var _w = clamp(abs(obj_player1.x - obj_player2.x), 640, room_width);
// Set the view width
view_wview[0] = lerp(view_wview[0], _w, 0.5);
// Set the view height based on the view PORT aspect ratio
view_hview[0] = view_wport[0] * (view_hport[0] / view_wport[0]);
}
}
I did a variation on this a few builds ago, but added some values to X/Y port/view to start in the middle of background. It would still only stretch left. What am I doing wrong? this thing has me baffled.
 
T

Tofu Heavy Industries

Guest
I don't think they changed the background size at all in SS. They zoomed the whole field.
I think so, I could be describing incorrectly. But sadly I'm having trouble replicating the effect. I can't even find any tutorials online that mimic this effect.
 

TheouAegis

Member
Well essentially what they are doing is the same thing that Nintendo did with Super Smash Bros. You find the point in the middle of the two players. This will be the central focus point of the camera. Ideally that is. Now calculate the distance from the left-most bounding box of either player to the right most bounding box of either player. Set your view width to that. If it is smaller than your minimum view width, set it to the minimum instead. If it is larger than your maximum view width, set it to the max instead. Now set the view height based on your aspect ratio. Now find the distance from the lowest bounding box of either player to the highest bounding box of either player. If that distance is greater than the height of your view, set the view height accordingly. If it is greater than your max view height, set it to the max instead. Calculate the view width based on your aspect ratio. If it is larger than your maximum view width, set the view width to maximum and reset view height based on your aspect ratio, otherwise set your view width based on your ratio. Then set the xview and yview accordingly.
 
Top