• 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!

Scrolling a view

TheOnlyWRT

Member
Hello!

So, after watching a few tutorials in youtube about scrolling the view in a game and trying to write some code to do so i couldnt get it to work and decided to post the question here. This is the code i have been using:

Room Start:
Code:
_index  = 0;//index of the view you want to target
_width  = 960;//set the value port width
_height = 540;//set the value port height


view_enabled = true;//enable the view
view_set_visible(_index, true);//set it to be visible
view_set_wport(_index, _width);//assign the port width
view_set_hport(_index, _height);//assign the port height

//resize game window and center it
window_set_rectangle(display_get_width()/2-view_wport[_index] / 2,display_get_height()/2 - 3*view_hport[_index] / 2,_width,_height);
//resize the application surface (for gui purposes)
//surface_resize(application_surface,_width,_height);
surface_resize(application_surface,display_get_gui_width(),display_get_gui_height());

//create a camera
camera = camera_create_view(0, 0, _width, _height, 0, 0, -1, -1,_width/2, _height/2);

//assign the camera
view_set_camera(view_camera[_index],camera);

//set the gui size to match the view
display_set_gui_size(960, 540);
Create:
Code:
sizeWidth = 960;
sizeHeight = 540;

viewX = camera_get_view_border_x(view_camera[0]);
viewY = camera_get_view_border_y(view_camera[0]);
Step:
Code:
if(keyboard_check(vk_left)){
    
    //viewX -= 5;
    //camera_set_view_pos(view_camera[0], viewX, viewY);
    camera_set_view_speed(view_camera[0], -5, 0);
    
} else if(keyboard_check(vk_right)){
    
    //viewX += 5;
    //camera_set_view_pos(view_camera[0], viewX, viewY);
    camera_set_view_speed(view_camera[0], 5, 0);
    
} else if(keyboard_check(vk_up)){
    
    //viewY -= 5;
    //camera_set_view_pos(view_camera[0], viewX, viewY);
    camera_set_view_speed(view_camera[0], 0, -5);
    
} else if(keyboard_check(vk_down)){
    
    //viewY += 5;
    //camera_set_view_pos(view_camera[0], viewX, viewY);
    camera_set_view_speed(view_camera[0], 0, 5);
    
}
Thanks for your help!
 
Top