Hey,
I'm trying to make a Camera which boundaries are dynamically changed, based on the current position of the Camera Object.
I can't get it to work how it used to be and I found nothing in the internet or in this forum for my special problem.
I try to achieve that only certain parts of a level will be visible.
for example in the picture below the empty parts of the level should never be visible, but i can't get it working the right way.
example Level for specified boundaires
The Camera Object itself is clamped to the room borders, so it can't get outside the room.
Here is the Code i got so far for the Camera Object:
Create event:
Step event:
End Step event:
Script scr_CamBound_y:
Script scr_update_Camera_y:
The scripts scr_CamBound_x and scr_update_Camera_x and basically the same like scr_CamBound_y and scr_update_Camera_y.
the problem i get is that the boundaries change not fast enough (that means you see parts of the level which should be not seen)
and the camera gets stuck at the top boundary untill the next boundary is defined, which is obviously not what i wanted.
if I snap the boundaries directly without smoothing the camera towards it, it doesn't look nice.
I hope you understand what i mean, because my english is not the best. ^^
can anyone help me? or does anyone have other suggestions to solve this problem? I would be very thankful.
I'm trying to make a Camera which boundaries are dynamically changed, based on the current position of the Camera Object.
I can't get it to work how it used to be and I found nothing in the internet or in this forum for my special problem.
I try to achieve that only certain parts of a level will be visible.
for example in the picture below the empty parts of the level should never be visible, but i can't get it working the right way.
example Level for specified boundaires
The Camera Object itself is clamped to the room borders, so it can't get outside the room.
Here is the Code i got so far for the Camera Object:
Create event:
GML:
lock_x_left = false;
lock_x_right = false;
lock_y_top = false;
lock_y_bot = false;
x_cord_left = 0;
x_cord_right = 0;
y_cord_top = 0;
y_cord_bot = 0;
GML:
if(instance_exists(Player)) {
//move camera x
if (lock_x_left&&!lock_x_right) x += (x_cord_left - x) * .4;
else if(!lock_x_left&&lock_x_right) x += (x_cord_right - x) * .4;
else x += (Player.x - x) * .2;
//move camera y
if (lock_y_top&&!lock_y_bot) y += (y_cord_top - y) * .150;
else if(!lock_y_top&&lock_y_bot) y += (y_cord_bot - y) * .150;
else y += (Player.y - y) * .075;
//define boundaries
scr_CamBound_y(0,1024,0,"top",0);
scr_CamBound_y(1024,3072,256,"top",0);
scr_CamBound_y(3072,4096,512,"top",0);
scr_CamBound_y(4096,4680,256,"top",0);
scr_CamBound_y(4680,4864,512,"top",0);
scr_CamBound_y(4864,6656,768,"top",0);
scr_CamBound_y(6656,8192,1024,"top",0);
scr_CamBound_y(8320,12800,1536,"top",0);
scr_CamBound_y(12800,13056,1792,"top",0);
scr_CamBound_y(0,2560,512,"bot",0);
scr_CamBound_y(2560,4096,768,"bot",0);
scr_CamBound_y(4096,5888,1024,"bot",0);
scr_CamBound_y(5888,7936,1280,"bot",0);
scr_CamBound_y(7936,11264,1792,"bot",0);
scr_CamBound_y(11264,13056,2048,"bot",0);
scr_CamBound_x(0,256,1024,"right",0);
scr_CamBound_x(1024,1536,8192,"right",0);
scr_CamBound_x(512,768,2560,"left",0);
scr_CamBound_x(1264,1792,7936,"left",0);
}
GML:
///set view position
view_object[0] = noone;
view_xview[0] = x-view_wview[0]/2;
view_yview[0] = y-view_hview[0]/2;
view_xview[0] = max(0, min(room_width-view_wview[0],view_xview[0]) );
view_yview[0] = max(0, min(room_width-view_hview[0],view_yview[0]) );
GML:
///scr_CamBound_y(x1,x2,y,top/bot,view_number);
//x1 - x2 -> range where the bound should be applied
//y -> bound limit applied
//view_number -> the number of the view applied to camera
//additions to get to view borders
xview_add = view_wview[argument4]/2;
yview_add = view_hview[argument4]/2;
if(x+xview_add>=argument0&&x-xview_add<argument1 ) {
if(argument3 == "top") {
scr_update_Camera_y(true,false,argument2+yview_add,0);
}
if(argument3 == "bot") {
scr_update_Camera_y(false,true,0,argument2-yview_add);
}
}
GML:
///scr_update_Camera_y(lock_y_top,lock_y_bot,y_cord_top,y_cord_bot);
//lock_y_top -> lock the top boundary
//lock_y_bot -> lock the bot boundary
//y_cord_top -> the top position the camera will be locked on
//y_cord_bot -> the bottom position the camera will be locked on
//Lock Y Top
if(argument0) {
y_cord_top = argument2;
if(y<y_cord_top) lock_y_top = true; //move Camera if outside boundary
else lock_y_top = false; //free Camera if inside boundary
}
//Lock Y Bottom
if(argument1) {
y_cord_bot = argument3;
if(y>y_cord_bot) lock_y_bot = true; //move Camera if outside boundary
else lock_y_bot = false; //free Camera if inside boundary
}
the problem i get is that the boundaries change not fast enough (that means you see parts of the level which should be not seen)
and the camera gets stuck at the top boundary untill the next boundary is defined, which is obviously not what i wanted.
if I snap the boundaries directly without smoothing the camera towards it, it doesn't look nice.
I hope you understand what i mean, because my english is not the best. ^^
can anyone help me? or does anyone have other suggestions to solve this problem? I would be very thankful.
Last edited: